Accessing Ms Access Using Java  PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews Microsoft Access
Written by Twinkle   
Monday, 31 December 2007

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

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

6. Connect to the database

Connection con = DriverManager.getConnection
(URL,userid,password);
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.*;
import java.io.*;

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

class JdbcDemo
{

public static void main(String args[]){

new JdbcDemo1();
}
}


User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews

Last Updated ( Saturday, 20 September 2008 )
 
Next >