Accessing Ms Access Using Java

by : Twinkle

Step by step guide:

1.Create a database in ms access and add a table
2.Add columns to the table.
3.Go to control panel->Administrative Tools
->JDBC-> System DSN
4.In System DSN tab click on add ,choose
Microsoft access driver ,then you will get a
dialog box opened ODBC Microsoft access setup
mention the data source name in it and in
databases click on select button and choose
your .mdb file that is created in step1.

5.Register the driver using


6.Connect to the database

Connection con = DriverManager.getConnection
url=" Jdbc:Odbc:"

userid and password are empty in case of MS access.if it oracle default userid is "scott" password is "tiger".

Ex: Connection con = DriverManager.getConnection
( "Jdbc:Odbc:msac", "","");

Source Code

import java.sql.*;

class JdbcDemo1
Connection con;
Statement stmt;
ResultSet rs;
con = DriverManager.getConnection( "Jdbc:Odbc:msac", "","");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM Table1");
while ( {
String x = rs.getString("name");
int s = rs.getInt("age");
}catch(SQLException e){
System.out.println("Hello World!"+e);
}catch(ClassNotFoundException e){

class JdbcDemo

public static void main(String args[]){

new JdbcDemo1();