JDBC Driver Type1 without DSN for MSAccess database

Below example describe how to establish database connection using JDBC Driver1 without DSN on windows. I am using MS-Access database.

Step 1: First your create a database "db1.mdb" on d:sample folder
Step 2: Create emp table as below -
Table Name - emp
eid (pK) Text,
ename Text,
ecity Text,
esalary number
and insert a record eid-"a001", ename-"am Kumar", ecity- "Delhi", esalary-77777

Step 3: Write below source code in your project and run it -

package pkg1;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Logger;
public class App1 {
public Connection setupConnection()
Connection con = DriverManager.getConnection("jdbc:odbc:Driver=
{Microsoft Access Driver (*.mdb)};Dbq=d:sampledb1.mdb");
return con;
catch (Exception e) {
public void dispEmp(){
Connection con=setupConnection();
Statement st=con.createStatement();
ResultSet res=st.executeQuery("select * from emp");
System.out.println(res.getString(1)+"  "+res.getString(2)+"  "+res.getString(3)+"  "+res.getString(4));con.close();
catch (Exception e) {
System.out.println("error in fetching data");
public static void main(String[] args)
new App1().dispEmp();

Previous Next

Share your valuable comment

Name :
Email Id : [ We will not publish your email id ]
Your Comment : [ Maximum 200 chars ]
Enter Security code :

Comment by : Kerem October 3rd, 2015
Comment : This could not poibssly have been more helpful!

Comment by : anupama May 16th, 2013
Comment : It gives me error.... java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)

Comment by : shankar kumar March 2nd, 2013
Comment : I was not aware of this feature. Thanks a lot.