Connect to a database via JDBC-ODBC : Access « Database SQL JDBC « Java






Connect to a database via JDBC-ODBC

  
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class Main {

  public static void main(String args[]) throws Exception {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection c = DriverManager
        .getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=c:/access.mdb");

    ResultSet rs = c.createStatement().executeQuery("select objet from Employee");

    while (rs.next()) {
      System.out.println(rs.getString("objet"));
    }
    rs.close();
    c.close();
  }
}

   
    
  








Related examples in the same category

1.Create a connection to MS Access database