类库介绍:
UCanAccess 可以将mdb 文件的数据操作封装为传统的JDBC数据库操作。
mdb 库连接示例代码:
String path = "D:/demo.mdb";
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
} catch(ClassNotFoundException cnfex) {
LOGGER.error("Problem in loading or registering MS Access JDBC driver");
cnfex.printStackTrace();
}
try {
String dbURL = "jdbc:ucanaccess://" + path + ";memory=true";
connection = DriverManager.getConnection(dbURL, null, "168168");
statement = connection.createStatement();
String sql = "select a.ID, a.Name from Person a ";
resultSet = statement.executeQuery(sql);
while(resultSet.next()) {
// POJO create
Result result = new Result(resultSet.getString(1),
resultSet.getString(2));
}
} catch(SQLException sqlex){
sqlex.printStackTrace();
} finally {
try {
if(null != connection) {
resultSet.close();
statement.close();
connection.close();
}
} catch (SQLException sqlex) {
sqlex.printStackTrace();
}
}
参考:
UCanAccess官网:http://ucanaccess.sourceforge.net/site.html
参考示例:https://www.benchresources.net/jdbc-msaccess-database-connection-steps-in-java-8/