Java Utililty Methods JDBC Derby Connection

List of utility methods to do JDBC Derby Connection

Description

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

Method

intgetSize2()
get Size
Connection conn = DriverManager.getConnection(protocol + dbName + ";create=true");
String sql = "select count(*) from whore2";
PreparedStatement ps = conn.prepareStatement(sql);
ResultSet rs = ps.executeQuery();
rs.next();
int id = rs.getInt(1);
rs.close();
ps.close();
...
ArrayListgetTables(File database)
get Tables
String DB_CONNECTION_STRING = "jdbc:derby:" + database;
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Connection conn = (Connection) DriverManager.getConnection(DB_CONNECTION_STRING);
DatabaseMetaData dbmd = conn.getMetaData();
ResultSet rs = dbmd.getTables(null, null, null, null);
ArrayList<String> tables = new ArrayList<String>();
while (rs.next()) {
    if (rs.getString("TABLE_SCHEM").equals("APP"))
...
ResultSetprintStats(String statstring)
Executes an arbitrary SQL query and returns the result.
boolean successful = true;
try {
    System.out.println("Connected to database " + dbName);
    s = conn.createStatement(); 
    statements.add(s);
    System.out.println("---Reading Statistics---");
    rs = s.executeQuery(statstring);
} catch (SQLException sqle) {
...
voidremoveUnitDB()
remove Unit DB
try {
    DriverManager.getConnection("jdbc:derby:memory:flexims;drop=true", "flexims", "123456");
} catch (SQLException e) {
intsaveContact(String fName, String lName)
save Contact
int pk = (fName + lName).hashCode();
loadDriver();
Connection conn = null;
ArrayList statements = new ArrayList();
PreparedStatement psInsert = null;
Statement s = null;
ResultSet rs = null;
try {
...
voidstartDerby()
start Derby
Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
Properties props = new Properties();
Connection conn = DriverManager.getConnection("jdbc:derby:memory:derbyDB;create=true", props);
Statement statement = conn.createStatement();
statement.execute("CREATE SCHEMA KMSADMIN");
statement.execute("SET SCHEMA KMSADMIN");
statement.execute("CREATE SEQUENCE RANGER_MASTERKEY_SEQ START WITH 1 INCREMENT BY 1");
String tableCreationString = "CREATE TABLE ranger_masterkey (id VARCHAR(20) NOT NULL PRIMARY KEY, create_time DATE,"
...
voidstartDerbyInEmbeddedMode()
Starts derby server in embedded mode.
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
DriverManager.getConnection("jdbc:derby:memory:unit-testing-jpa;create=true").close();
voidstopDerby()
stop Derby
try {
    DriverManager.getConnection("jdbc:derby:memory:derbyDB;drop=true");
} catch (SQLException ex) {