-
Notifications
You must be signed in to change notification settings - Fork 20
HSQLDB
HSQLDB (HyperSQL DataBase) is SQL relational database software written in Java. It offers a small, fast multithreaded and transactional database engine with in-memory and disk-based tables and supports embedded and server modes. It includes a powerful command line SQL tool and simple GUI query tools. In our project - we are using the embedded mode.
An embedded database system is a database management system (DBMS) which is tightly integrated with an application software that requires access to stored data, such that the database system is "hidden" from the application’s end-user and requires little or no ongoing maintenance. In this way , the only thing you need do to is to include the database to the project, and it will to the rest (of course, the programmer should use the JDBC library to connect to the embedded database). Simple as that! No need to search for external SQL database or create such one – Just import and connect!
Using Maven, you should add this dependency:
<dependency>
`<groupId>org.hsqldb</groupId>`
`<artifactId>hsqldb</artifactId>`
`<version>2.3.4</version>`
</dependency>
(the version is the newest version to the time of writing those lines. You should check Maven Repository for newer version)
In order to connect HSQLDB, you should use JDBC to connect to it. JDBC (Java Database Connectivity) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is part of the Java Standard Edition platform, from Oracle Corporation. It provides methods to query and update data in a database, and is oriented towards relational databases (From Wikipedia). For short, JDBC is the interface that allow programmer to connect to your database and run queries on it. This is an example of how to use the JDBC to connect HSQLDB:
`try {
Connection connection = DriverManager.getConnection("jdbc:hsqldb:file:" + DATABASE_PATH, "SA", "");
if (connection!= null)
System.out.println("Connection created successfully");
else
System.out.println("Problem with creating connection");
}catch (SQLException e) {
//handle error in connection
e.printStackTrace();
}
(Where the DATABASE_PATH is the path where you want the database will be placed). If the database is exist – it will connect to it, else it will create it. There are more ways and parameters that HSQLDB offers for connection, but I won't show them here. For more information, see links below.
In general, you can do operation on the database by creating Statement object form the connection (mentioned above). Each statement represents one or many SQL queries to do (SELECT, INSERT, UDPATE, DELETE, etc.), and by executing the Statement, it will send the SQL query to HSQLDB.
This Wiki display the main idea and use in HSQLDB (and JDBC). For more information, see links below:
- HSQLDB website: http://hsqldb.org/
- Good tutorial of using HSQLDB with JDBC: https://www.tutorialspoint.com/hsqldb/index.htm