Reputation: 17530
I'm developing a JSP project with NetBeans on a GlassFish server. The project uses a MS Access file as database. Where do I need to put the MDB file so JSP class can find it at runtime ?
My code
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
location = loc.getAbsolutePath().substring(0, loc.getAbsolutePath().length() - 2);
String filename = location + "\\myDB.mdb";
System.out.print(filename);
String database;
database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database += filename.trim() + ";DriverID=22;READONLY=true}";
c = (DBM) DriverManager.getConnection(database, "", "");
Upvotes: 0
Views: 760
Reputation: 3011
It doesn't really matter where you put the MDB file on the machine. The important part is that Java requires JDBC, the Java world equivalent to ODBC. (not exactly equivalent but you get me drift). But MS Access doesn't support JDBC, only ODBC. You need to set up ODBC as Sai said. Sun a long time ago created the JDBC-ODBC bridge as a bridge until all DBs created JDBC drivers (but not everyone did... like Access). It was meant to go away a long time ago but it is still here and you need to use it and configure it. There are a lot of examples on how to do this if you google "jdbc odbc bridge" but here is a link to this site to start:
But really, it is better for you to look this up. There are a lot of top quality sites that will show you. Look for a tutorial on Oracle first, then elsewhere. Stay away from India Rose or whatever it is called. It is the how not to do things.
I would suggest not using MS Access. Is there any reason that you are using MS Access other than familiarity? You would be better served to use a database that has native jdbc drivers. There are a lot of good quality databases having readily available JDBC drivers which are certainly much better quality and more stable than MS Access.
If you want something that is easy to start and use right out of the box, and has free query and database maintenance tools try MySQL. Just make sure you set it up to use the "InnoDB" option. That makes it behave as an 'acid' compliant database.
My preference is PostgreSQL, but it can be a little daunting at first to set up if you haven't used it before, and has no GUI tools built from the core team (it has some built from associate projects but nowhere near the number that is built is provided by MySQL). It has some configuration that needs to be done in order to allow TCP/IP connections, as well as some security configuration on how to allow users to connect. MySQL makes this less painful to the new user. In fact I think it is every bit as easy to use as MS Access. (FWIW I use Postgres because I think the DB engine is a better quality with more horsepower for bigger projects... like an open source Oracle).
There are other free ones out there but MySQL is likely one that you can use easily if you are moving from MS Access.
Upvotes: 1
Reputation: 6738
You should need to setup DSN which get connection. See below steps;
Upvotes: 1