码迷,mamicode.com
首页 > 编程语言 > 详细

windows下创建h2集群,及java集成详细步骤

时间:2017-08-15 11:24:06      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:string   win   java   详细   man   void   org   date   varchar   

1.下载h2包,解压

技术分享

2.cmd操作,进入bin目录

技术分享

3.创建两个目录

技术分享

 

4.建立集群

输入以下命令(需要进入h2的bin目录)

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.浏览器查看集群

http://192.168.30.50:8081

或者http://192.168.30.50:8082

技术分享

技术分享

6.java连接

导入jar包

public static void main(String[] args) throws ClassNotFoundException, SQLException {
        String sourceURL = "jdbc:h2:tcp://localhost:9101,localhost:9102/testCluster";// H2DB mem
                                                                    // mode
        String user = "sa";
        String key = "";
        Class.forName("org.h2.Driver");// HSQLDB Driver
        Connection conn = DriverManager.getConnection(sourceURL, user, key);// 把驱动放入连接
        Statement stmt = conn.createStatement();
        stmt.execute("CREATE TABLE mytable(name VARCHAR(100),sex VARCHAR(10))");
        // 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();
    }

 

windows下创建h2集群,及java集成详细步骤

标签:string   win   java   详细   man   void   org   date   varchar   

原文地址:http://www.cnblogs.com/youlangta/p/7363820.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!