Vote
0
How to access Microsoft Access database from JDBC
Angsuman Chakraborty
October 25th, 2003
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;
return DriverManager.getConnection(databaseURL, "", "");
}
Filed under Database, Java Software, Microsoft, Technology |
|
RSS 2.0 |
Trackback this Article
|
Email this Article
You may also like to read |




































October 12th, 2004 at 4:44 am
and if the database have password?
March 28th, 2006 at 5:20 am
[...] Previously I had provided the gist of how to access MS Access database from JDBC using JDBC-ODBC bridge. Today I will elaborate on that and provide you with two sample classes. The first - AccessJDBCUtil.java defines a method which provides you with a connection to the ms access database. The second - AccessJDBCTest.java uses the first to execute any given query (DDL & DML supported) on any ms access database and displays the result on console. [...]
August 23rd, 2006 at 11:40 pm
hi angsuman,
your code was really useful. everything makes sense..
but i would like you to throw some light on how you constructed the dburl..
if i am right your code does not require the data source name..
i would like to know what your url means and how to construct such an url..
August 24th, 2006 at 8:56 am
> if i am right your code does not require the data source name..
Yes, the beauty of it is that it doesn’t require datasource name.
> i would like to know what your url means and how to construct such an url..
Just reuse the code I have provided. It is the format which jdbc-odbc bridge driver understands and converts to appropriate format for underlying odbc layer. In short just reuse my code.
July 7th, 2007 at 11:56 pm
It is fine to know the conection of ODBC to MS ACCESS in Program.Buti wul’d like to know how to go control panel and then to ODBC and to give the
details of DNS name and select the required .mdb file.
I am sure u r going to give me the correct informatin.
July 15th, 2007 at 5:56 am
the same question as venkat i tried using control panel but wen i ran the program it showed sql exception error…
tell me how to establish connection b/w ms access and jdbc through control panel (odbc data source name )
July 16th, 2007 at 6:25 am
i Want to access my Microsoft access file. file exist on my local mechine… can any one give me example code for the same… the executed code
August 3rd, 2007 at 3:06 am
how to connect ajsp file with ms access….usinf jdbc….can u send me the tags whis is used
November 23rd, 2007 at 8:20 am
im trying to run applet with jdbc in an html file with the internet browser but the applet is opening but the database is not getting connected …..
November 23rd, 2007 at 7:59 pm
You need to use either a type 3 (A net-protocol fully Java technology-enabled driver translates JDBC API calls into a DBMS-independent net protocol which is then translated to a DBMS protocol by a server. This net server middleware is able to connect all of its Java technology-based clients to many different databases. The specific protocol used depends on the vendor. In general, this is the most flexible JDBC API alternative.) or type 4 (A native-protocol fully Java technology-enabled driver converts JDBC technology calls into the network protocol used by DBMSs directly. This allows a direct call from the client machine to the DBMS server and is a practical solution for Intranet access. Since many of these protocols are proprietary the database vendors themselves will be the primary source for this style of driver.) JDBC driver to connect properly.
June 3rd, 2008 at 11:37 pm
i want to access data in excel to MS access how to write a code for this in java
August 21st, 2008 at 7:29 pm
helu guys, could anyone give me a code…
sample like JAVA connecting to MA Access Database…
lets says a simple library system…
you can email me thru claiven2000@gmail.com
tnx guys in advance..it will help me alot