The Simplest Way To Link Your Java Program To Access Database

The simplest way to do this is to have Netbeans and Microsoft access that are compatible. Both of them should be 64bit or 32bit,otherwise you may be forced to configure the odbc-jdbc bridge.


  • Create a database in microsoft access, name it learnconnectiondb
  • Create a new project with the name learnconnection


package learnconnection;
import java.sql.*;
public class learnconnection {
    Connection conn;
    Statement st;
    ResultSet rs;
    public learnconnection(){
    connect();
    }
    public void connect(){
        try{
            String driver="sun.jdbc.odbc.JdbcOdbcDriver";
   Class.forName(driver);
   String db="jdbc:odbc:learnconnectiondb";
   conn=DriverManager.getConnection(db);
   st=conn.createStatement();
   String sql="select * from Ksa";
   rs=st.executeQuery(sql);
   while(rs.next()){
       System.out.println("\n"+rs.getString("ID")+"\t"+rs.getString("Name")+"\t"+rs.getString("section")+"\t"+rs.getString("county"));
     
   }
   }catch(Exception e){
   System.out.println(e.getMessage());}
    }


    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new learnconnection();
       
}
 
}
Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
Powered by Blogger.