creating jdbc odbc connection without creating the DSN in MS ACCESS

Adesh singh picture Adesh singh · Jan 4, 2013 · Viewed 12k times · Source

I am trying to make the connection between java and ms access database. I want to make the connection without creating the DSN. I am using the following code but it is throwing the exception "Data source name not found exception "

     try
     { 
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

     Connection con=DriverManager.getConnection("Jdbc:Odbc:Driver={Microsoft Access
     Driver(*.mdb)}; dbq=d:/newfolder/db11.mdb");
     Statement st=con.createStatement();
     }
     catch(Exception ex)
    {
     ex.printStackTrace();
     }

Answer

AsirC picture AsirC · Jan 4, 2013

it should be like this:

Connection con = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=/db.accdb");