List of utility methods to do JDBC Derby Connection
Connection | getConnection() get Connection if (connection != null) { return connection; } else { try { String host = "jdbc:derby://localhost:1527/RosterDB"; String uName = "app"; String uPass = "app"; connection = DriverManager.getConnection(host, uName, uPass); ... |
Connection | getDatabaseConnection() This function establishes the connection to the database. Connection con = null; try { con = DriverManager.getConnection(DBASE_URL, databaseUsername, databasePassword); } catch (SQLException sqle) { String msg = "Cannot establish a connection to the database"; throw new Exception(msg, sqle); } finally { return con; ... |
Connection | getDefaultDerbyConnection() get Default Derby Connection return DriverManager.getConnection("jdbc:default:connection"); |
Connection | getDerbyConnection(String filename) get Derby Connection try { File db = new File(filename); boolean exists = false; if (!db.exists()) { for (File child : db.getParentFile().listFiles()) { if (child.getName().startsWith(db.getName())) { exists = true; System.setProperty("derby.stream.error.file", "error.txt"); System.setProperty("derby.system.home", db.getParent()); System.setProperty("derby.storage.pageSize", "32768"); Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); String url = String.format("jdbc:derby:%s", db.getAbsolutePath()); if (!exists) { url = url.concat(";create=true"); return DriverManager.getConnection(url); } catch (ClassNotFoundException e) { throw new RuntimeException("Failed to load Derby db driver!", e); } catch (SQLException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException("Failed to load Derby db driver!", e); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to load Derby db driver!", e); |
String | getDerbyDatabaseProperty(Statement derbyStatementForQuerying, String propertyKey) get Derby Database Property ResultSet rs = derbyStatementForQuerying .executeQuery("VALUES SYSCS_UTIL.SYSCS_GET_DATABASE_PROPERTY('" + propertyKey + "')"); try { return rs.next() ? rs.getString(1) : null; } finally { rs.close(); |
Connection | getDerbyUnitConnection() get Derby Unit Connection String url = "jdbc:derby:memory:flexims;create=true"; Properties props = new Properties(); props.setProperty("user", "flexims"); props.setProperty("password", "123456"); return DriverManager.getConnection(url, props); |
Driver | getDriver(String className) get Driver try { Driver driver = (Driver) Class.forName(className).newInstance(); if (className.equals("org.apache.derby.jdbc.EmbeddedDriver")) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { DriverManager.getConnection("jdbc:derby:;shutdown=true"); ... |
Connection | getLocalConnection() Get the connection to the local database. return DriverManager.getConnection("jdbc:default:connection"); |
Vector | getRowsFromDatabase(Connection con, int numberOfRows, boolean reuseConnection, String driver, String dsn, String user, String password, String tableName, String whereString, String orderByString, String groupByString) get Rows From Database if (reuseConnection == false) { con.close(); con = getConnection(driver, dsn, user, password); Vector temp = new Vector(); String query = null; String[] separated; Statement stmt = con.createStatement(); ... |
Set | getSessionIds() get Session Ids HashSet<String> ids = new HashSet<String>(); Class.forName(DRIVER_CLASS); Connection con = null; try { con = DriverManager.getConnection(DEFAULT_CONNECTION_URL); PreparedStatement statement = con.prepareStatement("select " + ID_COL + " from " + TABLE); ResultSet result = statement.executeQuery(); while (result.next()) { ... |