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

voidcleanUpTest(Statement s, String[] testObjects)
Drop the test objects passed in as a string identifying the type of object (e.g.
for (int i = 0; i < testObjects.length; i++) {
    try {
        s.execute("drop " + testObjects[i]);
    } catch (SQLException se) { 
voidcloseConnection()
close Connection
try {
    if (stmt != null) {
        stmt.close();
    if (conn != null) {
        DriverManager.getConnection(dbURL + ";shutdown=true");
        conn.close();
} catch (SQLException sqlExcept) {
    System.out.println(sqlExcept.getMessage());
voidcloseDB()
close DB
if (framework.equals("embedded")) {
    try {
        DriverManager.getConnection("jdbc:derby:" + dbName + ";shutdown=true");
    } catch (SQLException se) {
        if (((se.getErrorCode() == 45000) && ("08006".equals(se.getSQLState())))) {
        } else {
            System.err.println("Derby did not shut down normally");
            printSQLException(se);
...
ConnectioncreateAndOpen(String databaseName)
create And Open
return DriverManager.getConnection("jdbc:derby:" + databaseName + ";create=true");
voidcreateConnection()
create Connection
try {
    System.setProperty("derby.system.home", System.getProperty("user.home") + "/DiscoHub");
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
    conn = DriverManager.getConnection(dbURL);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) {
    System.out.println("error " + ex.getMessage());
ConnectioncreateConnection(String userName, String password)
create Connection
try {
    Class.forName(driverName);
    Properties dbProps = new Properties();
    dbProps.put("user", userName);
    dbProps.put("password", password);
    conn = DriverManager.getConnection(dbURL + dbLocation, dbProps);
} catch (Exception except) {
    System.out.print("Could not connect to the database with username: " + userName);
...
voidcreateXATransactionView(Statement s)
Create a view that allows useful inspection of the active global transactions.
s.execute("create view XATESTUTIL.global_xactTable as " + "select  cast(global_xid as char(2)) as gxid,"
        + " status, "
        + " CAST (case when first_instant is NULL then 'NULL' else 'false' end AS VARCHAR(8)) as readOnly, "
        + " cast (username as char(10)) as username, type " + " from syscs_diag.transaction_table");
voiddeleteTestData()
delete Test Data
java.sql.Connection jdbcConn = openJDBCConnection();
java.sql.Statement jdbcStmt = jdbcConn.createStatement();
String sql = "drop table " + TABLE_NAME;
jdbcStmt.execute(sql);
jdbcStmt.close();
jdbcConn.close();
booleanexistsInSessionTable(String id, boolean verbose)
exists In Session Table
Class.forName(DRIVER_CLASS);
Connection con = null;
try {
    con = DriverManager.getConnection(DEFAULT_CONNECTION_URL);
    PreparedStatement statement = con
            .prepareStatement("select * from " + TABLE + " where " + ID_COL + " = ?");
    statement.setString(1, id);
    ResultSet result = statement.executeQuery();
...
ConnectiongetConnection()
Get a connection to the database.
return DriverManager.getConnection(DB_CONN_STRING);