gpt4 book ai didi

java - 捕获 HsqlException

转载 作者:太空宇宙 更新时间:2023-11-04 13:57:11 26 4
gpt4 key购买 nike

我想捕获该异常,但它不起作用。基本上,以下代码的作用是调用方法 createConnection() 来尝试建立与数据库的连接。如果数据库不存在,则抛出两个异常。我捕获了两者,但仅适用于 SQLException,不适用于 HsqlException

    try {
createConnection();
} catch (HsqlException | SQLException e1) {
System.out.println("Not exist the DataBase. Creating a new one.");
new CreateDB();
}finally{
try {
createConnection();
} catch ( SQLException | org.hsqldb.HsqlException e) {
e.printStackTrace();
System.out.println("Some big error ocurred. Please contact me.");
System.exit(0);
}
}

createConnection() 中的代码

void createConnection() throws SQLException, org.hsqldb.HsqlException{
conn = DriverManager.getConnection(URL + DB_FILE +";ifexists=true");
}

异常(exception)是

    2015-04-17T15:12:37.834+0100  SEVERE  could not reopen database
org.hsqldb.HsqlException: Database does not exists: db\dogsRus
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(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)
at org.hsqldb.jdbc.JDBCConnection.<init>(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ac.uk.jov2.dogsRus.database.DataBaseUtil.createConnection(DataBaseUtil.java:90)
at ac.uk.jov2.dogsRus.database.DataBaseUtil.<init>(DataBaseUtil.java:54)
at ac.uk.jov2.dogsRus.database.DataBase.<init>(DataBase.java:16)
at ac.uk.jov2.dogsRus.Application.<init>(Application.java:28)
at ac.uk.jov2.dogsRus.Application.main(Application.java:388)

最佳答案

这不是您正在调用的方法引发的异常。

2015-04-17T15:12:37.834+0100 SEVERE could not reopen database org.hsqldb.HsqlException: Database does not exists: db\dogsRus at org.hsqldb.error.Error.error(Unknown Source)

它是 HSQLDB 内部生成的 Java 记录器消息,在本例中,它默认发送到 stderr(恰好是控制台)。请参阅有关如何处理记录器消息的指南。

http://hsqldb.org/doc/2.0/guide/management-chapt.html#mtc_jdc_logging

关于java - 捕获 HsqlException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29702134/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com