How to connect to HSQLDB database using a JDBC program?



HSQLDB is a relational database management system implemented in pure Java. You can easily embed this database to your application using JDBC. Or you can use the operations separately.

Installing HSQLDB:

  • Download the latest version of HSQLDB database.

  • Install HSQLDB following the steps given in HSQLDB Tutorial.

Make sure that the HSQLDB database is up and running. The URL to connect to this database is jdbc:hsqldb:hsql://host_name/database_name and the driver class name is org.hsqldb.jdbc.JDBCDriver. Download the driver and set classpath to it.

Example

Following JDBC program establishes a connection with HSQL database.

import java.sql.Connection; import java.sql.DriverManager; public class ConnectDatabase {    public static void main(String[] args) {       Connection con = null;       try {          //Registering the HSQLDB JDBC driver          Class.forName("org.hsqldb.jdbc.JDBCDriver");          //Creating the connection with HSQLDB          con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/testdb", "SA", "");          if (con!= null) {             System.out.println("Connection created successfully");          }else{             System.out.println("Problem with creating connection");          }       } catch (Exception e) {          e.printStackTrace(System.out);       }    } }

Output

Connection created successfully
Updated on: 2019-07-30T22:30:25+05:30

898 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements