Search code examples
javajdbcconnectionhsqldb

How to use org.hsqldb.jdbc.JDBCConnection class of HSQLDB API


I understand it is useful to use org.hsqldb.server.Server class when creating a hsqldb server programmatically.

I always used java SDK class (java.sql.Connection) to connect to the server and I feel it is enough to connect whether the server is memory-based or file-based.

Why do we need org.hsqldb.jdbc.JDBCConnection class of hsqldb API?


Solution

  • There is no 'class' java.sql.Connection: it is an interface. JDBC is an API that consists of interfaces (and some supporting classes). Those interfaces need to be implemented by each and every JDBC driver to actually be able to do anything.

    When you use HSQLDB, you use its implementation of java.sql.Connection called org.hsqldb.jdbc.JDBCConnection; this contains the specifics of how HSQLDB works (something which JDBC itself doesn't know). However usually you only need to access it through the interface defined in JDBC; that is even preferable for portability.

    So in short, if it wasn't for org.hsqldb.jdbc.JDBCConnection, you would not even be able to connect to a HSQLDB.