javadatabaseembeddingh2

Embedding the Java h2 database programmatically


At the moment we use HSQLDB as an embedded database, but we search for a database with less memory footprint as the data volume grows.

Derby / JavaDB is not an option at the moment because it stores properties globally in the system properties. So we thought of h2.

While we used HSQLDB we created a Server-object, set the parameters and started it. This is described here (and given as example in the class org.hsqldb.test.TestBase).

The question is: Can this be done analogous with the h2 database, too? Do you have any code samples for that? Scanning the h2-page, I did not find an example.


Solution

  • From the download, I see that the file tutorial.html has this

    import org.h2.tools.Server;
    ...
    // start the TCP Server
    Server server = Server.createTcpServer(args).start();
    ...
    // stop the TCP Server
    server.stop();