January 27, 2017

How to check if database exists while connecting in HSQLDB

In HSQLDB, if while providing connection string if the database does not exists, it creates a new database. However, lets say if we want to restrict HSQLDB to create new Database and only connect to exists one and if not present then throw back an exception, we can specify a connection property ifexists=true. This will allow only to connect to an existing database and avoid creating new one. Also, if db does not exists it will throw an exception.

 Connection c = DriverManager.getConnection( "jdbc:hsqldb:file:testdb;ifexists=true", "SA", "");  

No comments:

Post a Comment