1. Download H2 package, unzip
2.cmd operation, go to Bin directory
3. Creation of two directories
4. Building a Cluster
Enter the following command (required to enter the bin directory of H2)
JAVA-CP "h2-1.4.195.jar;%h2drivers%;%classpath%" Org.h2.tools.server-tcpallowothers-tcpport 9101-weballowothers- WebPort 8081-basedir D:\database\h2Cluter\h2_1
JAVA-CP "h2-1.4.195.jar;%h2drivers%;%classpath%" Org.h2.tools.server-tcpallowothers-tcpport 9102-weballowothers- WebPort 8082-basedir D:\database\h2Cluter\h2_2
JAVA-CP h2-1.4.195.jar org.h2.tools.createcluster-urlsource "Jdbc:h2:tcp://127.0.0.1:9101/testcluster"-urlTarget " Jdbc:h2:tcp://127.0.0.1:9102/testcluster "-user" sa "-serverlist" 127.0.0.1:9101,127.0.0.1:9102 "
5. Browser View Cluster
http://192.168.30.50:8081
or http://192.168.30.50:8082.
6.java Connection
Importing JAR Packages
Public Static voidMain (string[] args) throws ClassNotFoundException, SQLException {String sourceURL="Jdbc:h2:tcp://localhost:9101,localhost:9102/testcluster";//h2db Mem//ModeString user ="SA"; String Key=""; Class.forName ("Org.h2.Driver");//HSQLDB DriverConnection conn = drivermanager.getconnection (sourceURL, user, key);//put the drive into the connectionStatement stmt =conn.createstatement (); Stmt.execute ("CREATE TABLE mytable (name VARCHAR), Sex VARCHAR (Ten )"); //String sql = "Select VALUE from Information_schema." SETTINGS WHERE//name= ' CLUSTER ' ";Stmt.executeupdate ("INSERT into MyTable VALUES (' Steven Stander ', ' Male ')"); Stmt.executeupdate ("INSERT into MyTable VALUES (' Elizabeth Eames ', ' female ')"); Stmt.executeupdate ("DELETE from mytable WHERE sex= ' Male '"); Stmt.close (); Conn.close (); }
Create H2 clusters under Windows, and Java integration detailed steps