Windows 7 and Access 2010, Help Please...
I recently graduated from school with a Bachelors in Software Engineering...but one thing we didn't do much of was database connectivity, and what we did do was only with MySQL (we used Netbeans).
I'm looking at writing an application for my parents for maintaining their blood pressure and I currently have it working nicely with but it writes to a .doc file. I'd like to make it into a database, using Access since they already have it on their PC, but cannot seem to get the JDBC-ODBC connection to work properly.
I'm running Windows 7, and I have Access 2010. I've gone through using the SYSWOS64 odbccad32.exe file, and it shows up but I still get the error that there is no default driver.
Does anyone have a sample code with/without a database?
Here's what I have, I had gone through and created a BASIC database....just for testing purposes.
--------------------------------------------------------------------------------------------------------------------------------------------
public static void main(String[] args) {
//This application will test a connection to a MS Access DB
//jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=<full path to mdb file>;Uid=;Pwd=;"
Connection con;
Statement st = null;
String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
try {
Class.forName(driver);
File f = new File(System.getProperty("user.dir"));
con = DriverManager.getConnection("jdbc:odbc:Driver={Mic rosoft Access Driver (*.mdb, *.accdb)}; DBQ=C:\\Users\\Joe Chorba\\Documents\\BP_DATABASE.accdb", "", "");
//st = con. createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
ResultSet rs = st.executeQuery("select * from Table1");
System.out.println(rs);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
Re: Windows 7 and Access 2010, Help Please...
Can you provide the full stack trace and message for the error.
That error usually implies that your connection string is incorrect somewhere.
Re: Windows 7 and Access 2010, Help Please...
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:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.j ava:3073)
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:582)
at java.sql.DriverManager.getConnection(DriverManager .java:185)
at javaapplication10.JavaApplication10.main(JavaAppli cation10.java:32)
Re: Windows 7 and Access 2010, Help Please...
That's Microsoft complaining rather than JDBC.
So it's found the driver (that is the JDBC/ODBC one) but ODBC is having problems.
Have you tried creating a DSN for the database?
That would shorten it to jdbc:odbc:<dsn name>.
Re: Windows 7 and Access 2010, Help Please...
So I'm changing this line:
con = DriverManager.getConnection("jdbc:odbc:Driver={Mic rosoft Access Driver (*.mdb, *.accdb)}; DBQ=C:\\Users\\Joe Chorba\\Documents\\BP_DATABASE.accdb", "", "");
to:
con = DriverManager.getConnection("jdbc:odbc:<dsn name>", "","");
???
Is this right?
1 Attachment(s)
Re: Windows 7 and Access 2010, Help Please...
java.sql.SQLException: [Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc .java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.j ava:3073)
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:582)
at java.sql.DriverManager.getConnection(DriverManager .java:185)
at javaapplication10.JavaApplication10.main(JavaAppli cation10.java:32)
BUILD SUCCESSFUL (total time: 0 seconds)
I added a screen capture so you can see the ODBC Administrator Screens...
Attachment 2697
Re: Windows 7 and Access 2010, Help Please...
It's possible the JDBC/ODBC bridge is having a problem, though I suspect it's the ODBC driver itself vs Access 2010, though I have no idea at all how that functions.
You might need to trawl the Microsoft site and see.