I want catch that exception but it doesn't work. Basically what it does the follow code is call method createConnection() for try to make the connection to the database. If the database doesn't exist throws two exception. I catch both, but only works for the SQLException and not for the 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);
}
}
the code from createConnection()
void createConnection() throws SQLException, org.hsqldb.HsqlException{
conn = DriverManager.getConnection(URL + DB_FILE +";ifexists=true");
}
and the exception is
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)