How to access MS Access database from JDBC?

btw, I dint test it. I just post it for my reference. thanks Angsuman Chakraborty.

How to access MS Access database from JDBC?

 private static final String accessDBURLPrefix = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";   
private static final String accessDBURLSuffix = ";
DriverID=22;READONLY=false}";
// Initialize the JdbcOdbc Bridge Driver
static {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(ClassNotFoundException e)
{
System.err.println("JdbcOdbc Bridge Driver not found!");
}
}
/** Creates a Connection to a Access Database */
public static Connection getAccessDBConnection(String filename) throws SQLException
{
filename = filename.replace('\', '/').trim();
String databaseURL = accessDBURLPrefix + filename + accessDBURLSuffix;
// System.err.println("Datebase URL: " + databaseURL);
return DriverManager.getConnection(databaseURL, "", "");
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s