The HSQLDB is used for interactive user access to databases, including creation of a database, inserting or modifying data, or querying the database.
The product is currently being used as a database and persistence engine in many Open Source Software projects and even in commercial projects and products. In its current version it is extremely stable and reliable. It is best known for its small size, ability to execute completely in memory, its flexibility and speed.
Pre-Requisites:Variable name: | JAVA_HOME |
Variable value: | C:\Program Files\Java\jdk1.6.0_11 |
Variable name: | PATH |
Variable value: | C:\Program Files\Java\jdk1.6.0_11\bin |
Variable name: | CLASSPATH |
Variable value: | C:\hsqldb-2.2.9\lib\hsqldb.jar |
Here we can find small connection window, there we have to provide the connection details. Here I have taken file catalog for the URL that means my database engine memory is file.
CREATE TABLE IF NOT EXISTS salarydetails ( EmpID varchar(6) PRIMARY KEY, Salary INT NOT NULL, Bonus INT NOT NULL, Increment INT NOT NULL, )
INSERT INTO salarydetails VALUES ('54601A', 10000, 5000, 2000); INSERT INTO salarydetails VALUES ('54602A', 12000, 500, 2000); INSERT INTO salarydetails VALUES ('54603A', 11000, 500, 2000);
####Use two appenders, one to log to console, another to log to a file log4j.rootCategory=info, stdout, R ####First appender writes to console log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout #Pattern to output the caller's file name and line number. log4j.appender.stdout.layout.ConversionPattern=%5p[%t] (%F%L) - %m%n ####Second appender writes to a file log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=C:\\JAVA\\Log\\import.log #Control the maximum log file size log4j.appender.R.MaxFileSize=10000KB #Archive log files (one backup file here) log4j.appender.R.MaxBackupIndex=10 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p%t %c - %m%n
package org.javaVillage.hsqldb; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; /** * @author www.javaworkspace.com * */ public class ConnectHSQLDB { public static void main(String[] args) { Connection connection = null; ResultSet resultSet = null; Statement statement = null; try { Class.forName("org.hsqldb.jdbcDriver"); connection = DriverManager.getConnection( "jdbc:hsqldb:file:C:/JavaInstallation/HSQLDB/DB", "SA", ""); statement = connection.createStatement(); resultSet = statement .executeQuery("SELECT Salary FROM SALARYDETAILS WHERE Emptitle='54601A'"); while (resultSet.next()) { System.out.println("EMPLOYEE Salary:" + resultSet.getString("Salary")); } } catch (Exception e) { e.printStackTrace(); } finally { try { resultSet.close(); statement.close(); connection.close(); } catch (Exception e) { e.printStackTrace(); } } } }