Saturday, November 12, 2011

JDBC connectivity with MS access

import java.sql.*;
public class email
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn = DriverManager.getConnection("jdbc:odbc:emaildb", "admin", "");
Statement st = cn.createStatement();
ResultSet rs = st.executeQuery("select * from emaillists");
System.out.println("Name\tEmail\tSite\n");
while(rs.next())
{
System.out.print(rs.getString(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.print(rs.getString(3)+"\n");
}
rs.close();
st.close();
cn.close();
}
catch(Exception e)
{
System.out.print(e);
}
}
}