UCanAccess - 使用 keepMirror 后无法重新连接到 Access 数据库

UCanAccess - Unable to reconnect to Access database after using keepMirror

我正在尝试使用 UCanAccess 读取 Access 数据库。

代码正在运行,但由于数据库很大,速度非常慢。由于数据库很少更改,我尝试使用

中的 keepMirror 建议

; .

connection = DriverManager.getConnection(UcanaccessDriver.URL_PREFIX + databaseFile + ";keepMirror=/some/dir/test/resources/db-mirror/mirror");

在第一个 运行 上,应用程序运行良好,并在上面的目录中创建了镜像文件。然而,在随后的 运行 秒中,我得到以下异常:

Exception in thread "main" java.lang.RuntimeException: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 error in script file line: 289 /some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE constraint already exists on the set of columns in statement [CREATE CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at de.gdfsuezenergie.stromnev.enet.ENETConnector.init(ENETConnector.java:69) at de.gdfsuezenergie.stromnev.Main.setUp(Main.java:374) at de.gdfsuezenergie.stromnev.Main.main(Main.java:165) at de.gdfsuezenergie.stromnev.MainTest.main(MainTest.java:9) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144) Caused by: net.ucanaccess.jdbc.UcanaccessSQLException: UCAExc:::3.0.6 error in script file line: 289 /some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE constraint already exists on the set of columns in statement [CREATE CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:264) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:270) at de.gdfsuezenergie.stromnev.enet.ENETConnector.createConnection(ENETConnector.java:86) at de.gdfsuezenergie.stromnev.enet.ENETConnector.init(ENETConnector.java:57) ... 8 more Caused by: java.sql.SQLException: error in script file line: 289 /some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE constraint already exists on the set of columns in statement [CREATE CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCConnection.(Unknown Source) at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source) at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at net.ucanaccess.jdbc.DBReference.getHSQLDBConnection(DBReference.java:440) at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:231) ... 12 more Caused by: org.hsqldb.HsqlException: error in script file line: 289 /some/dir/test/resources/db-mirror/mirror-783471167 a UNIQUE constraint already exists on the set of columns in statement [CREATE CACHED TABLE <TABLE DEF> ON DELETE CASCADE ON UPDATE CASCADE)] at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.scriptio.ScriptReaderText.readDDL(Unknown Source) at org.hsqldb.scriptio.ScriptReaderBase.readAll(Unknown Source) at org.hsqldb.persist.Log.processScript(Unknown Source) at org.hsqldb.persist.Log.open(Unknown Source) at org.hsqldb.persist.Logger.open(Unknown Source) at org.hsqldb.Database.reopen(Unknown Source) at org.hsqldb.Database.open(Unknown Source) at org.hsqldb.DatabaseManager.getDatabase(Unknown Source) at org.hsqldb.DatabaseManager.newSession(Unknown Source) ... 19 more Caused by: org.hsqldb.HsqlException: a UNIQUE constraint already exists on the set of columns at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.ParserTable.addTableConstraintDefinitions(Unknown Source) at org.hsqldb.StatementSchema.getResult(Unknown Source) at org.hsqldb.StatementSchema.execute(Unknown Source) at org.hsqldb.Session.executeCompiledStatement(Unknown Source) ... 28 more

据我所知,这因此违反了对此缓存 table 的某些限制,我不明白的是为什么要 运行 宁此脚本。我认为创建镜像的全部意义在于我不需要重新应用任何脚本?

有人知道如何正确读取镜像吗?

注意:

=> 为简洁起见,我跳过了 table 定义。

我设法让它工作,但它有点老套。基本上是通过从镜像脚本中删除唯一约束,它最终成功通过了。遗憾的是我不了解这些数据,所以需要弄清楚它是否仍然正确,但我相信它是。

谢谢大家指点!非常感谢。

已知当 Access 数据库中的 table 为给定列定义了多个唯一索引时会发生此问题,例如主键索引(Primary=Yes,Unique=Yes)另一个单独的唯一索引(主要=否,唯一=是)。

Access 本身对此没有任何问题,但 HSQLDB(UCanAccess 将其用于其后备数据库)不允许在一组列上使用多个唯一约束。

最好的解决办法是在Access中打开.accdb或.mdb数据库,去掉多余的非Primary唯一索引。