I am working on my matric java programming project and I need to be able to save data to a Microsoft Access database 2000 format. The following code is the constructor method for my array manager object.
import java.sql.*; public class DBManager { private Connection conn; public DBManager() { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String dbname = "database.mdb"; conn = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" + dbname); System.out.println("Connection successful"); Statement s = conn.createStatement(); String name = "erin"; String query = "SELECT * FROM Table1 WHERE name = \"" + name + "\";"; System.out.println(query); s.execute(query); ResultSet rs = s.getResultSet(); } catch (Exception e) { System.out.println("ERROR: " + e); e.printStackTrace(); } } }
And I am getting the following error:
ERROR: java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified 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.java:3072) at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323) at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174) at java.sql.DriverManager.getConnection(DriverManager.java:579) at java.sql.DriverManager.getConnection(DriverManager.java:243) at DBManager.<init>(DBManager.java:15) at NewClass.main(NewClass.java:13)
This is my main method to run the above code:
public class NewClass { public static void main(String[] args) { DBManager m = new DBManager() ; } }
I am using NetBeans IDE 7.0.1 to program this. Could anyone help me identify the problem with this code, which according to the error message is this line:
conn = DriverManager.getConnection("jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" + dbname);
If any more information is required, please ask.
Thanks