Showing posts with label HSQLDB. Show all posts
Showing posts with label HSQLDB. Show all posts

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", "");  

March 20, 2013

How to make primary key column with auto increment in HSQLDB TEXT Table

IDENTITY keyword can be use to make the table column both as primary key and auto increment.
An IDENTITY column is always treated as the primary key for the table (as a result, multi-column primary keys are not possible with an IDENTITY column present).
For example:


CREATE TEXT TABLE test (
  test_ID INTEGER IDENTITY,
  test_VERSION varchar(10) NOT NULL 
) ;

Insert into test (test_version) values (`5`);

If you run the above code, it will automatically insert incremented value in test_ID column with given test_version column, as follows;

test_ID  test_version
1  5