connection to MS access database
Hi, I am trying to get a connection to a microsoft acces database.
I have written a DAO factory to get acces to different databases. I have installed a driver to get connection to an MySql database and everything goes fine.
Now I am trying to get connection to an MS Access database, but I can't.
Do I have to install a driver too? How can I access to my database (access 2007).
I try with this code:
Code:
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c=DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver(*.mdb)};DBQ=C:\\Trouw2.mdb","","");
But I get following error:
Quote:
java.sql.SQLException: [Microsoft][ODBC-stuurprogrammabeheer] De naam van de gegevensbron is niet gevonden en er is geen standaardstuurprogramma opgegeven
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6956)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7113)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.j ava:3072)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOd bcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDrive r.java:174)
at java.sql.DriverManager.getConnection(DriverManager .java:579)
at java.sql.DriverManager.getConnection(DriverManager .java:221)
at DAO.MSDAOFactory.getConnection(MSDAOFactory.java:3 4)
at DAO.MSGameDAO.test(MSGameDAO.java:33)
at HelloWorld.main(HelloWorld.java:30)
Exception in thread "main" java.lang.NullPointerException
at DAO.MSGameDAO.test(MSGameDAO.java:39)
at HelloWorld.main(HelloWorld.java:30)
Java Result: 1
Re: connection to MS access database
When you say "installed a driver", do you mean you included the JDBC connector jar in your class path? Every database requires it's own JDBC connector, you will need one for Access too.
Re: connection to MS access database
Quick Google translation:
"The name of the data source is not found and no default driver specified"
Which means that it cannot find a data source matching the name given, which is an ODBC error.
Does that mdb exist?
Re: connection to MS access database
Oh, and what versions of OSes and Java are you on (including whether 32 or 64 bit).