Microsoft Access database with Eclipse [message #529014] |
Thu, 22 April 2010 11:57  |
Eclipse User |
|
|
|
Hi, I want to access a .dmb database with eclipse.
I'm still learning about that.
Here is the code I use to test
import java.sql.*;
import java.io.*;
public class ConnectDB
{
public static Connection con;
public static final String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
public static final String url = "jdbc.odbc:" + "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=";
String path;
public ConnectDB()
{
path = "c:\test.mdb";
}
public void go()
{
makeConnection();
closeConnection();
}
private void makeConnection()
{
System.out.println("Opening databse... \n");
try
{
Class.forName(driver);
con = DriverManager.getConnection(url + path);
}
catch(Exception ex)
{
System.out.println("Error opening the database!");
System.out.println(ex);
System.exit(0);
}
System.out.println("Success!");
}
private void closeConnection()
{
System.out.println("\nClosing database.");
try
{
con.close();
}
catch (Exception ex)
{
System.out.println("Error closing the database");
System.out.println(ex);
}
}
public static void main(String[] args)
{
ConnectDB test = new ConnectDB();
test.go();
}
}
However I got the error
Opening databse...
Error opening the database!
java.sql.SQLException: No suitable driver found for jdbc.odbc:DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c: est.mdb
I'm using 64-bit windows. Because 64-bit doesn't have Microsoft Access Driver, I have setup the DSN for the driver in 32-bit by going to "%WINDIR%\SysWOW64\odbcad32.exe"
But I'm still getting the error.
How should I change the line "public static final String url = "jdbc.odbc:" + "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=";" to make it work? basically, how to make it look into the 32-bit driver, not 64-bit. Is there any setting I need to change?
Thank you.
|
|
|
|
Powered by
FUDForum. Page generated in 0.07888 seconds