检测由于损坏而导致HSQLDB初始化失败

时间:2016-11-09 17:06:34

标签: java hsqldb

启动嵌入式HSQLDB时,它有时会记录异常:

2016-11-08 10:35:27 INFO h.d.H.ENGINE user:NA company:NA remotehost:NA dataFileCache open start
2016-11-08 10:35:27 INFO h.d.H.ENGINE user:NA company:NA remotehost:NA dataFileCache open end
2016-11-08 10:35:31 ERROR h.d.H.ENGINE user:NA company:NA remotehost:NA statement error processing log /home/jetty/test/testdb/test.dbline: 87137
org.hsqldb.HsqlException: user lacks privilege or object not found: PUBLIC.FROM
        at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.error.Error.error(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.SchemaManager.getUserTable(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.scriptio.ScriptReaderText.processStatement(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.scriptio.ScriptReaderText.readLoggedStatement(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.persist.ScriptRunner.runScript(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.persist.ScriptRunner.runScript(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.persist.Log.processLog(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.persist.Log.open(Unknown Source) ~[hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.persist.Logger.openPersistence(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.Database.reopen(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.Database.open(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.DatabaseManager.getDatabase(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.DatabaseManager.newSession(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source) [hsqldb-2.2.7.jar:2.2.7]
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:95) [HikariCP-2.4.3.jar:na]
        at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:101) [HikariCP-2.4.3.jar:na]
        at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:314) [HikariCP-2.4.3.jar:na]
        at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:171) [HikariCP-2.4.3.jar:na]
        at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:436) [HikariCP-2.4.3.jar:na]
        at com.zaxxer.hikari.pool.HikariPool.access$500(HikariPool.java:65) [HikariCP-2.4.3.jar:na]
        at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:567) [HikariCP-2.4.3.jar:na]
        at com.zaxxer.hikari.pool.HikariPool$PoolEntryCreator.call(HikariPool.java:560) [HikariCP-2.4.3.jar:na]
        at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.7.0_51]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.7.0_51]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.7.0_51]
        at java.lang.Thread.run(Unknown Source) [na:1.7.0_51]
2016-11-08 10:35:31 INFO h.d.H.ENGINE user:NA company:NA remotehost:NA checkpointClose start
2016-11-08 10:35:31 INFO h.d.H.ENGINE user:NA company:NA remotehost:NA dataFileCache commit start
2016-11-08 10:35:31 INFO h.d.H.ENGINE user:NA company:NA remotehost:NA checkpointClose end
2016-11-08 10:35:32 INFO c.x.p.d.u.DataSourceFactory user:NA company:NA remotehost:NA Database connection is OK!
2016-11-08 10:35:32 INFO c.x.p.d.u.DataSourceFactory user:NA company:NA remotehost:NA Initialising data source: Liquibase
2016-11-08 10:35:32 INFO c.x.p.d.u.DataSourceFactory user:NA company:NA remotehost:NA HSQLDB used

HSQLDB似乎吞下了这些例外 这导致我们的java代码继续运行,即使数据库可能已损坏。

有没有办法捕捉这些例外?
或者是一个Java API调用来验证数据库是否正确启动了?

1 个答案:

答案 0 :(得分:1)

异常消息:

org.hsqldb.HsqlException: user lacks privilege or object not found: PUBLIC.FROM

表示在数据库的.log文件中,引用了.log文件的第87137行中名为FROM的表。由于表格不能被称为FROM,因此表明存在损坏的行。

当数据库未正确关闭且.log文件的最后一行未同步到磁盘时,可能会发生这种情况。引擎会忽略该点的.log文件条目。

您可以选择将hsqldb.full_log_replay=true添加到连接属性,以便抛出异常并中止连接尝试。然后,您可以查看和编辑.log文件以删除损坏的行。 如果你想