Create a connection to MS Access database : Access « Database SQL JDBC « Java






Create a connection to MS Access database

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

public class Main {
  // private static final String URL = "jdbc:odbc:TestDB";

  private static final String USERNAME = "admin";

  private static final String PASSWORD = "welcome";

  private static final String DRIVER = "sun.jdbc.odbc.JdbcOdbcDriver";

  private static final String URL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\Database\\testdb.mdb;}";

  public static void main(String[] args) throws Exception {

    Class.forName(DRIVER);
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

    connection.close();
  }
}

   
    
  








Related examples in the same category

1.Connect to a database via JDBC-ODBC