最佳答案
英文原文
you can use
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 ,"","");
中文翻译
你可以使用
的Class.forName( " sun.jdbc.odbc.JdbcOdbcDriver中" );
//将此设置为您计算机上的MS Access DB
String filename =" d:/java/mdbTEST.mdb" ;
String database =" jdbc:odbc:Driver = {Microsoft Access Driver(* .mdb)}; DBQ =" ;
database + = filename.trim()+" ; DriverID = 22; READONLY = true}" ; //添加到最后
//现在我们可以从DriverManager获得连接
Connection con = DriverManager.getConnection(database," " ," " );
you can use
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 ,"","");
你可以使用
的Class.forName( " sun.jdbc.odbc.JdbcOdbcDriver中" );
//将此设置为您计算机上的MS Access DB
String filename =" d:/java/mdbTEST.mdb" ;
String database =" jdbc:odbc:Driver = {Microsoft Access Driver(* .mdb)}; DBQ =" ;
database + = filename.trim()+" ; DriverID = 22; READONLY = true}" ; //添加到最后
//现在我们可以从DriverManager获得连接
Connection con = DriverManager.getConnection(database," " ," " );
参考答案2
参考答案3
An alternative - JDBC to ODBC Bridge - which has a client/server architecture is also available...
This means the Java application and Access database can reside on different machines.
The following link will give you an idea of what goes where --
参考答案4
public class NewClass {
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL = "jdbc:mysql://localhost/databasename";
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
public void dataQuery(String queryData) {
Class.forName(DRIVER);
connection = DriverManager.getConnection(DATABASE_URL, "root", "");
statement = connection.createStatement();
resultSet = statement.executeQuery(queryData);
while (resultSet.next()) {
System.out.println(resultSet.getObject(1));
}
}
catch (Exception e) {
System.out.println("error Accessing");
}finally {
try {
resultSet.close();
statement.close();
connection.close();
} catch (Exception exception) {
System.out.println("error closing ");}
}
}
}
参考答案5
You can use ODBC connection to connect to Access Database from Java.
See the following example
参考答案6
Now that the JDBC-ODBC Bridge has been removed from Java (since Java SE 8), future readers should consider using the UCanAccess JDBC driver instead. For more information see