Java Utililty Methods JDBC H2 Connection

List of utility methods to do JDBC H2 Connection

Description

The list of methods to do JDBC H2 Connection are organized into topic(s).

Method

voidcreateDBWithTB(String db)
create DB With TB
Connection conn = DriverManager.getConnection("jdbc:h2:" + path + ":" + db, userName, pass);
boolean flag;
Statement statement;
statement = conn.createStatement();
flag = statement.execute(CREATETB0);
assert flag;
statement = conn.createStatement();
flag = statement.execute(CREATETB1);
...
voiddeleteDatabase()
delete Database
if ("sqlite".equals(JDBC_URL.substring(5, 11))) {
    deleteDatabaseSQLITE();
} else {
    deleteDatabaseH2();
voiddeleteDatabaseH2()
delete Database H
Connection conn = DriverManager.getConnection(JDBC_URL, "sa", "");
Statement stmt = conn.createStatement();
try {
    stmt.execute("DROP ALL OBJECTS DELETE FILES");
} finally {
    stmt.close();
    conn.close();
ConnectiongetConnection()
get Connection
Connection connection = null;
try {
    Class.forName("org.h2.Driver");
    connection = DriverManager.getConnection(
            "jdbc:h2:D:/work/workspace/fork/gs-serving-web-content/initial/data/fdata;DATABASE_TO_UPPER=false",
            "h2", "h2");
} catch (SQLException e) {
    e.printStackTrace();
...
ConnectiongetH2Connection(String dbname)
get H Connection
return getConnection(DB_H2_DRIVER, DB_H2_CONNECTION, dbname, DB_H2_USER, DB_H2_PASSWORD);
ConnectiongetH2Connection(String filename)
get H Connection
try {
    System.setProperty("h2.serverCachedObjects", "200000");
    Class.forName("org.h2.Driver");
    return DriverManager.getConnection(String.format("jdbc:h2:%s;DB_CLOSE_ON_EXIT=FALSE;TRACE_LEVEL_FILE=3",
            new File(filename).getAbsolutePath()), "sa", "");
} catch (ClassNotFoundException e) {
    throw new RuntimeException("ERROR: Couldn't load H2 db driver");
} catch (SQLException e) {
...
booleanisH2DbAlreadyRunning()
is H Db Already Running
try {
    Connection connection = DriverManager.getConnection(h2DbJdbcUrl, "sa", null);
    connection.close();
    return true;
} catch (Exception ex) {
    return false;
voidrollback(Savepoint sp)
rollback
try {
    h2Connection.rollback(sp);
} catch (Exception e) {
    throw new RuntimeException("DB error on rollback: " + e.toString());
voidsetAutoCommit(Boolean b)
set Auto Commit
try {
    h2Connection.setAutoCommit(b);
} catch (Exception e) {
    throw new RuntimeException("DB error: failed to set auto commit: " + e.toString());