如何使用 JDBC 从 Java 连接到 Access 数据库?
OP评论中提供的代码
public static Connection getConnection() throws SQLException {
// connection object
Connection con = null;
// database url
String connectionString = "jdbc:odbc:Driver= "
+ "{Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + dbPath;
try {
Class.forName(driver);
con = DriverManager.getConnection(connectionString);
} catch (ClassNotFoundException ex) {
System.out.println("connot load driver class");
return con;
}
}
最佳答案
你可以使用
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "d:/java/mdbTEST.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database+= filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection( database ,"","");
引用http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=2691&lngWId=2
关于java - 如何使用 JDBC 从 Java 连接到 Access 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8504197/