How to access Microsoft Access database from JDBC

By Angsuman Chakraborty, Gaea News Network
Saturday, October 25, 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, "", "");
    }  
Discussion
July 19, 2010: 3:40 am

it’s clear that people want to connect with others by location, as well as share experiences and seek recommendations by those who are well informed


Mehul sharma
June 1, 2010: 5:54 am

hii,

i want to upload my excel file data in to database table at back end using SQL server . Can u please help me out for to send me the query for this.

Thanks & Regards
Mehul


Jaspinder
May 10, 2010: 9:57 pm

i want to access the data of MS-Access table via java AWT Components. Pls help.


lokesh pareek
March 2, 2010: 11:51 am

please send me code for
set values in database(access) through JSP.


vyella
January 22, 2010: 1:04 am

how can i install msaccess connecting to a database using jdbc…….


Sudhir S. Shinde
January 8, 2010: 6:08 am

Please Give me Answers of my questions when i ask the questions

i m hopeful for that.


dhamu
December 12, 2009: 4:17 am

I want, how to make jdbc connection with access in java. and i want simple example for this. and how to write jdbc connection program using queries. pls sent mail to my id. plsssss.
with regards,
Dhamu MCA


Kartik
December 6, 2009: 1:27 pm

Hi

i want to show a MS-Access table in the java frame please hekp me and provide the code its important for my project

November 19, 2009: 5:37 am

How to access intranet database on internet and intranet both .


shivraj
October 27, 2009: 9:23 am

How to connect Access,Oracle,MySql Database with JDBC

July 6, 2009: 1:48 pm

R/s,
I am create simple frame in java in which just take some textboxes for eno,ename and take one button Save. and create ms-access database for this frame with name emp(e_no and e_name are field).
i am create jdbc odbc connection. but it is not working.
so please tell me how it connect.
plase replay me on my email id.
Thanking You.
nilesh


hardik
June 4, 2009: 1:12 pm

hi
i want to access the codes to connect mysql and ms access from java with some discription

February 13, 2009: 3:16 pm

How to connect the Java with Ms Excel database

February 13, 2009: 2:53 pm

How to connect java with MS Excel Database,

pls send me the code or mail me

josephgudapati@gmail.com


udit sharma
February 11, 2009: 9:39 am

plz help me in connection of java program with ms access….


Karthikeyan
January 22, 2009: 1:27 pm

my best wishes for this code.thank you to he person who posted this code.


joe
January 4, 2009: 4:18 am

Hi,
for MS Access 2007 and DNS-less connection I use the following URL:

jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:/temp/db.accdb


ryan
August 21, 2008: 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


veena
June 3, 2008: 11:37 pm

i want to access data in excel to MS access how to write a code for this in java

November 23, 2007: 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.


manjunath
November 23, 2007: 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 …..


chock
August 3, 2007: 3:06 am

how to connect ajsp file with ms access….usinf jdbc….can u send me the tags whis is used


shuaib
July 16, 2007: 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


anirudh
July 15, 2007: 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 )


venkat
July 7, 2007: 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.

August 24, 2006: 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.


ashwanth
August 23, 2006: 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..

March 28, 2006: 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. [...]


Carlos Espinosa
October 12, 2004: 4:44 am

and if the database have password?

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :