Posts

Showing posts from September, 2016

Java Embedded H2 Tutorial

Image
This tutorial includes JAVA code to simplify the creation and use of H2 embedded databases. The example 'little main test' creates an embedded database  on c:/tmp, named 'h2db' using username 'sa' and password 'sasa', in server mode. Then it connects to it, does nothing (little main test does nothing, make it grow bigger), disconnects and then frees the resources used by the database before ending its execution. public static void main(String[] args) throws IOException, ClassNotFoundException, SQLException { // Instance an embedded H2 EmbeddedH2 h2db = new EmbeddedH2(); //Optional: set SQL mode //h2db.setH2SQLMode("MYSQL"); //Optional, open it as server on port: h2db.setPort(9876); h2db.init( new File("f:/tmp"), "h2db", "sa", "sasa"); System.out.println("OK."); // Create a connection Connection con=h2db.getC