Skip to content

Instantly share code, notes, and snippets.

@theotherian
Last active April 16, 2018 16:37
Show Gist options
  • Save theotherian/6096578 to your computer and use it in GitHub Desktop.
Save theotherian/6096578 to your computer and use it in GitHub Desktop.
hsqldb basics
An example of creating an in-memory HSQLDB server
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<!-- set url to target/hsql:mem:test so that files are written to build dir -->
<property name="connection.url">jdbc:hsqldb:target/hsql:mem:test</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
import org.hsqldb.server.Server;
public class ServerApplication {
public static void main(String[] args) throws Exception {
Server server = new Server();
server.setDatabaseName(0, "test");
// set location to target/mem:test so that files are written to build dir
server.setDatabasePath(0, "target/mem:test");
server.setSilent(false);
server.setTrace(true);
server.start();
// do stuff
server.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment