We can access the data from MS-Access by using java application
steps to access the data from MS-Access
1.create table in ms-access with table1
2. create DSN for ms-access
control panel---->Data Sources(ODBC)---->Add--->microsoft Access Driver(*.mdb,*.accdb)--->give Datasource(aes)--->select-->choose access filename---->finish
above DSN name we have to use in java application
3.Write java application
import java.sql.*;
class first
{
public static void main(String arg[]) throws Exception
{
sun.jdbc.odbc.JdbcOdbcDriver d=new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(d);
System.out.println("Drivers are loaded");
Connection con=DriverManager.getConnection("jdbc:odbc:aes");
System.out.println("Connection is established");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from table1");
while(rs.next())
{
String s1=rs.getString(1);
String s2=rs.getString(2);
System.out.println(s1+" "+s2);
}
con.close();
}
}
steps to access the data from MS-Access
1.create table in ms-access with table1
2. create DSN for ms-access
control panel---->Data Sources(ODBC)---->Add--->microsoft Access Driver(*.mdb,*.accdb)--->give Datasource(aes)--->select-->choose access filename---->finish
above DSN name we have to use in java application
3.Write java application
import java.sql.*;
class first
{
public static void main(String arg[]) throws Exception
{
sun.jdbc.odbc.JdbcOdbcDriver d=new sun.jdbc.odbc.JdbcOdbcDriver();
DriverManager.registerDriver(d);
System.out.println("Drivers are loaded");
Connection con=DriverManager.getConnection("jdbc:odbc:aes");
System.out.println("Connection is established");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from table1");
while(rs.next())
{
String s1=rs.getString(1);
String s2=rs.getString(2);
System.out.println(s1+" "+s2);
}
con.close();
}
}
No comments:
Post a Comment