MS没提供Jdbc驱动,有一个第三方的UcanAcess驱动包
<!-- https://mvnrepository.com/artifact/net.sf.ucanaccess/ucanaccess --> <dependency> <groupId>net.sf.ucanaccess</groupId> <artifactId>ucanaccess</artifactId> <version>5.0.0</version> </dependency>
连接单元测试:
@Test public void connectionTest() throws Exception { Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); final String microSoftAccessDataBaseLocation = "C:\\Users\\Administrator\\Documents\\sample.accdb"; final String UcanAccessConnectUrl = "jdbc:ucanaccess://" + microSoftAccessDataBaseLocation; Connection connection = DriverManager.getConnection(UcanAccessConnectUrl); System.out.println(connection); connection.close(); }
打印结果:
13:33:50.933 [main] DEBUG com.healthmarketscience.jackcess.Index - unsupported collating sort order SortOrder[2052(0)] for text index (Db=sample.accdb;Table=MSysObjects;Index=0), making read-only 13:33:50.950 [main] DEBUG com.healthmarketscience.jackcess.impl.DatabaseImpl - Could not find expected index on table MSysObjects (Db=sample.accdb) 13:33:50.968 [main] DEBUG com.healthmarketscience.jackcess.impl.DatabaseImpl - Finished reading system catalog. Tables: [user] (Db=sample.accdb) net.ucanaccess.jdbc.UcanaccessConnection@5b03b9fe[C:\Users\Administrator\Documents\sample.accdb]