Reputation: 43
can someone help me to let my database connected to java. I've been trying this for hours but i still got this exception : "java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified?"
public Connector() {
Connection con;
Statement st;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=Database.mdb");
st = con.createStatement(1004, 1008);
} catch (Exception e)
e.printStackTrace();
}
}
Here's the exception that i got:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
Upvotes: 4
Views: 1185
Reputation: 123654
Your Java code is running under a 64-bit JVM (Java Virtual Machine) and trying to use the older "Jet" ODBC driver Microsoft Access Driver (*.mdb)
. That won't work because the older "Jet" driver is only available to 32-bit applications. You either need to
Run your Java program under a 32-bit JVM, or
Download and install the 64-bit version of the newer "Access Database Engine ('ACE')" from here and then use the ODBC Driver name Microsoft Access Driver (*.mdb, *.accdb)
when running your code under a 64-bit JVM.
Also, remember that the JDBC-ODBC Bridge has been removed from Java 8 so continuing to use it is not very "future-friendly". For an alternative, see
Manipulating an Access database from Java without ODBC
Upvotes: 2