Create H2 clusters under Windows, and Java integration detailed steps

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.