List of utility methods to do JDBC HSQL Connection
Connection | createConnection() create Connection Connection result = null; try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); result = DriverManager.getConnection("jdbc:hsqldb:hsql://127.0.0.1:9001/commons", "SA", ""); } catch (Exception ex) { ex.printStackTrace(); return result; ... |
Connection | createHSQLDBConnection(String hsqldbName) Establish a database connection to a HSQL database (file system) try { Class.forName("org.hsqldb.jdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:hsqldb:file:" + hsqldbName, "sa", ""); return conn; } catch (Exception e) { System.err.println( ... |
void | createSchemasForHSQLDB(String dbName, String[] schemaNames) This will connect to the in-memory HSQL DB dbName and issue CREATE SCHEMA commands for each schema named in schemaNames . Class.forName(HSQL_DRIVER); Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:" + dbName, "sa", ""); Statement createSchema = conn.createStatement(); for (String schema : schemaNames) { createSchema.executeUpdate("CREATE SCHEMA " + schema + " AUTHORIZATION dba"); |
Connection | getConnection() get Connection Connection conn = null; try { Class.forName("org.hsqldb.jdbcDriver"); if (mode == SERVER_MODE) { conn = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost:" + PORT + "/" + DB_NAME, USER_NAME, PASSWORD); } else if (mode == STAND_ALONE_MODE) { conn = DriverManager.getConnection("jdbc:hsqldb:file:" + DB_PATH + DB_NAME, USER_NAME, PASSWORD); ... |
Connection | getDbConnection() get Db Connection Connection rc = DriverManager.getConnection("jdbc:hsqldb:mem:testDb", "sa", ""); return rc; |
void | createTweetTable() create Tweet Table Connection connection = getConnection(); Statement statement = connection.createStatement(); String query = "DROP TABLE IF EXISTS tweet"; statement.executeUpdate(query); query = "CREATE TABLE tweet (\n" + " id integer NOT NULL PRIMARY KEY,\n" + " user varchar(32) NOT NULL,\n" + " message varchar(140) NOT NULL,\n" + ");"; statement.executeUpdate(query); statement.close(); ... |
Connection | getHSQLConnection() get HSQL Connection Class.forName("org.hsqldb.jdbcDriver"); System.out.println("Driver Loaded."); String url = "jdbc:hsqldb:data/tutorial"; return DriverManager.getConnection(url, "sa", ""); |
void | printSchema() print Schema Class.forName("org.hsqldb.jdbcDriver"); Connection connection = DriverManager.getConnection("jdbc:hsqldb:data/tutorial", "sa", ""); Statement st = connection.createStatement(); DatabaseMetaData metaData = connection.getMetaData(); ResultSet results = metaData.getTables(null, null, null, new String[] { "TABLE" }); while (results.next()) { String tableName = results.getString(3); System.out.println("\n\n\n\nTable Name: " + tableName); ... |
boolean | stopHSQL() stop HSQL try { Statement statement = getConnection().createStatement(); statement.executeUpdate("SHUTDOWN;"); return true; } catch (SQLException ex) { ex.printStackTrace(); return false; |