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


    1.下载h2包,解压,创建server1  server2

    2.进入h2/bin目录

    cd h2/bin

    3.建立集群

    java -cp "h2-1.4.195.jar:$H2DRIVERS:$CLASSPATH" org.h2.tools.Server -tcpAllowOthers -tcpPort 9101 -webAllowOthers -webPort 8081 -baseDir /usr/local/soft/h2Cluster/server1
    java -cp "h2-1.4.195.jar:$H2DRIVERS:$CLASSPATH" org.h2.tools.Server -tcpAllowOthers -tcpPort 9102 -webAllowOthers -webPort 8082 -baseDir /usr/local/soft/h2Cluster/server2
    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"

     

    3.java集成

    public static void main(String[] args) throws ClassNotFoundException, SQLException {
            String sourceURL = "jdbc:h2:tcp://192.168.30.130:9101,192.168.30.130: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();
        }
  • 相关阅读:
    netbeans 快捷键
    Netbeans Platform的Lookup 边学边记
    Swing中的并发使用SwingWorker线程模式
    转:ExtJS:tabpanel 多个tab同时渲染问题
    NetBeans Platform Login Tutorial
    检测项目
    C#实现通过程序自动抓取远程Web网页信息
    WebClient类
    string字符串的方法
    WebClient的研究笔记认识WebClient
  • 原文地址:https://www.cnblogs.com/youlangta/p/7364150.html
Copyright © 2020-2023  润新知