List of utility methods to do JDBC H2 Connection
void | createDBWithTB(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); ... |
void | deleteDatabase() delete Database if ("sqlite".equals(JDBC_URL.substring(5, 11))) { deleteDatabaseSQLITE(); } else { deleteDatabaseH2(); |
void | deleteDatabaseH2() 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(); |
Connection | getConnection() 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(); ... |
Connection | getH2Connection(String dbname) get H Connection return getConnection(DB_H2_DRIVER, DB_H2_CONNECTION, dbname, DB_H2_USER, DB_H2_PASSWORD);
|
Connection | getH2Connection(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) { ... |
boolean | isH2DbAlreadyRunning() is H Db Already Running try { Connection connection = DriverManager.getConnection(h2DbJdbcUrl, "sa", null); connection.close(); return true; } catch (Exception ex) { return false; |
void | rollback(Savepoint sp) rollback try { h2Connection.rollback(sp); } catch (Exception e) { throw new RuntimeException("DB error on rollback: " + e.toString()); |
void | setAutoCommit(Boolean b) set Auto Commit try { h2Connection.setAutoCommit(b); } catch (Exception e) { throw new RuntimeException("DB error: failed to set auto commit: " + e.toString()); |