Contact: Web / Voice / Email / Tips
Simple Thoughts Blog - Java and Web Technologies

Simple solutions for complex problems.

 

How to access Microsoft Access database from JDBC

October 25th, 2003 by Angsuman Chakraborty

    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 | Email this Article

You may also like to read

»Access Microsoft Access Database From Java Using JDBC-ODBC Bridge - Sample Code
»Java, JSP, Servlet, JDBC - Back To The Basics Part 2
»HSQLDB Database Connection Close Doesn't Write to Disk - Solution
»What is The Best Database for a Souped Up Hashtable?
»Top 10 Java SE 6 Features
»Yet another object database on RDBMS backend: A new project
»The case for HSQLDB as RDBMS for Java Development
»Security Vulnerability: Firewall Site Exposes Sensitive Data Through phpMyAdmin
»UK Ministry of Defence Adapts Blackberry.. Is It Safe?
»Java Studio Creator 2 Early Access is available for free
»What happened to Reliable Systems ( iContract ) & MetaMata?
»Flaw in HSBC Online Banking Exposes 3 Million Customers
»Back Online...
»How to close all connections in HSQLDB (also prevents a locking defect)
»Java / J2EE Needs to Add Ease of Use (Redundant) Methods

10 Responses to “How to access Microsoft Access database from JDBC”

  1. Carlos Espinosa Says:

    and if the database have password?

  2. Access Microsoft Access Database From Java Using JDBC-ODBC Bridge - Sample Code -Simple Thoughts - Java and Web Technology Blog Says:

    [...] 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. [...]

  3. ashwanth Says:

    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..

  4. Angsuman Chakraborty Says:

    > 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.

  5. venkat Says:

    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.

  6. anirudh Says:

    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 )

  7. shuaib Says:

    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

  8. chock Says:

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

  9. manjunath Says:

    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 …..

  10. Angsuman Chakraborty Says:

    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.

Looking forward to hear your thoughts.



Please enter the code shown below ( to verify that you are human ) before you click Submit Comment.

No. 1 method to ethically increase your blog traffic and reach.

Translate

Translate to EnglishÜbersetzen Sie zum Deutsch/GermanPřeložit do Čech/CzechOversætte hen til Dansk/DanishKääntää jotta Finnish/FinnishLefordít -hoz Magyar/HungarianÞýða til Íslenska/IcelandicTraducir a Latinoamericano Español/Latin American Spanishtagapagsalin sa Filipino/FilipinoTłumaczyć wobec Polski/PolishA traduce la spre Român/RomanianPrevesti za Srpski/Serbiantolmačiti v slovenski/SlovenianÖversätta till Svensk/SwedishChyfieitha at Cymraeg/Welshtercüme etmek -e doğru Türk/TurkishPrevesti to Hrvatski/CroatianПревеждам към Българин/BulgarianTraduzca al Español/SpanishTraduisez au Français/FrenchTraduca ad Italiano/ItalianTraduza ao Português/Portuguese日本語に翻訳しなさい /Japanese한국어에게 번역하십시오/Korean中文翻译/Chinese Simplifiedترجمة الى العربية/ArabicVertaal aan het Nederlands/DutchΜεταφράστε στα ελληνικά/GreekПереведите к русскому/RussianOversetter til Norsk/Norwegian中文翻译/Chinese TraditionalTraduzir a Língua portuguesa brasileira/Brazilian PortugueseReddo ut Latin/Latin

Taragana Network

»Ctrl-S
»Enterprise Blog
»Free Book on Eye Care by Natural Therapy
»Health Care Blog
»Hot Computer Jobs Blog
»Pet Care & Grooming News and Tips
»Phil Law Blog
»Taragana - Software Outsourcing
»The Angsuman Chakraborty Blog
»The Diabetes Cure Blog
»The Eye Treatment Blog
»The Stem Cell Blog
»Weblog Hosting Blog
"Now he has departed from this strange world a little ahead of me. That means nothing. People like us, who believe in physics, know that the distinction between past, present, and future is only a stubbornly persistent illusion." - Albert Einstein