HSQLDB Intro

other languages: Italian

This article introduce HSQLDB, and give a summary,launching ad some usage examples.

Introduction

HSQLDB (HyperSQL Database) is a relational DB engine written in Java. It offers a fast, small Database engine which offers both in-memory and disk-based tables. Additionally, it include tools like a minimal web server HSQLDB is currently being used as database and persistence engine in many open source software projects (see).

Local copies of official documentation ( v.2.0 )

Launching – Running the server

You can start the server in different ways: as HSQL Server, as HTTP Server as HTTP Servlet or from Java Program.

The preferred way of running the DB Server (and the fastest one) is to launch the HSQL Server from command prompt

java -cp ../lib/hsqldb.jar org.hsqldb.server.Server --database.0 file:mydb --dbname.0 xdb

The above example launch HSQL Server ( org.hsqldb.server.Server ) with one database, named “xdb” ; backed on files named mydb.* ( in current prompt directory ). To launch the HTTP Server, replace the main class for the server with

org.hsqldb.server.WebServer

The server can also be launched as HTTP Servlet. this method also use the HTTP protocolit is used when a separated servlet engine (or application server) provides the access to the DB.

As we said the server can be launched from Java Program. The code below make an example of launch and execute statements.

Server hServer;
try{
  hServer = new Server( );
  hServer.setLogWriter( null );
  hServer.setSilent( true );

  // database name and set file storage
  hServer.setDatabaseName( 0, "xdb" );
  hServer.setDatabasePath( 0, "file:testdb" );

  // starts the database
  hServer.start();

  // now connect to the db
  Connecction conn = null;
  //
  try{
    Class.forName("org.hsqldb.jdbcDriver");
    // connect
    conn = DriverManager.getConnection(
      "jdbc:hsqldb:hsql://localhost/xdb", "sa", "");
    // execute statement
    conn.prepareStatement("drop table testtable;")
      .execute();
    conn.prepareStatement(
      "create table testtable ( id INTEGER, name VARCHAR ) ;" )
      .execute();

  } finally {
    // closing connection
    if( connection != null ) {
      conn.close();
    }
  }
} finally {
  // closing server
  if( hServer != null ){
    hServer.stop();
  }
}

For more detais see

Conclusions

This article explained rapidly how to use HSQLDB for common purposes. For whose needs clarification, follow references: main site: http://hsqldb.org/