Java JDBC H2 Connection createDBWithTB(String db)

Here you can find the source of createDBWithTB(String db)

Description

create DB With TB

License

Apache License

Declaration

public static void createDBWithTB(String db) throws SQLException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.*;

public class Main {
    public static final String path = System.getProperty("user.dir") + "/src/test/resources/h2db";
    public static final String userName = "root";
    public static final String pass = "xujianhai";
    public static final String CREATETB0 = " create table tb0(" + " order_id INT NOT NULL,"
            + " product_id INT NOT NULL," + " usr_id INT NOT NULL,"
            + " begin_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," + " end_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,"
            + " status INT," + " PRIMARY KEY(order_id)" + " )";
    public static final String CREATETB1 = " create table tb1(" + " order_id INT NOT NULL,"
            + " product_id INT NOT NULL," + " usr_id INT NOT NULL,"
            + " begin_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP," + " end_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,"
            + " status INT," + " PRIMARY KEY(order_id)" + " )";

    public static void createDBWithTB(String db) throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:h2:" + path + ":" + db, userName, pass);

        boolean flag;
        Statement statement;/*w  ww . j a  v  a 2s .  c o m*/

        // tb0
        statement = conn.createStatement();
        flag = statement.execute(CREATETB0);
        assert flag;

        // tb1
        statement = conn.createStatement();
        flag = statement.execute(CREATETB1);
        assert flag;

        conn.close();
    }
}

Related

  1. deleteDatabase()
  2. deleteDatabaseH2()
  3. getConnection()
  4. getH2Connection(String dbname)