Java Utililty Methods JDBC Connection Create

List of utility methods to do JDBC Connection Create

Description

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

Method

ConnectiongetSourceConnection(final Hashtable env)
Specialized getConnection() which uses the environment attributes for the source DB to initialize the connection
return getConnection(SOURCE_DB_URL_KEY, SOURCE_DB_USERNAME_KEY, SOURCE_DB_PASSWORD_KEY, SOURCE_DB_TYPE_KEY,
        SOURCE_DB_DRIVER_KEY, env);
StatementgetStatement(Map config)
get Statement
Class.forName(config.get("driver")).newInstance();
Connection connection = DriverManager.getConnection(config.get("url"), config.get("user"),
        config.get("password"));
return connection.createStatement();
ConnectiongetTargetConnection()
get Target Connection
return getConnection(dbResourceBundle.getString("targetDriver"),
        dbResourceBundle.getString("targetConnectionString"), dbResourceBundle.getString("targetUserName"),
        dbResourceBundle.getString("targetPassword"));
ConnectiongetTestDBConnection()
get Test DB Connection
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String url = "jdbc:ucanaccess://C:/users/cgrass/Desktop/" + "USM Marketing Application/Test Database/"
        + "test_USMMarketingIntelligenceDatabase.accdb";
Connection conn = DriverManager.getConnection(url);
return conn;
ConnectiongetTRECConnection()
get TREC Connection
Connection connection = null;
try {
    loadProperties();
    String location = properties.getProperty("db.location"); 
    DB_DRIVER = properties.getProperty("db.driver");
    DB_USER = properties.getProperty("db.username");
    DB_PASSWORD = properties.getProperty("db.password");
    URL = properties.getProperty(location + ".url_trec");
...
ConnectiongetUrlConnection()
get Url Connection
Connection connection = null;
checkprops();
Logger.global.log(Level.FINE, "DriverManager.getConnection(url)");
connection = DriverManager.getConnection(url);
Logger.global.log(Level.INFO, "DriverManager.getConnection(url) passed");
Logger.global.log(Level.FINE, "==============\n\n");
return connection;
ConnectiongetUserConnection()
get User Connection
Connection connection = null;
checkprops();
Logger.global.log(Level.FINE, "DriverManager.getConnection(url, usr, pwd)");
connection = DriverManager.getConnection(url, usr, pwd);
Logger.global.log(Level.INFO, "DriverManager.getConnection(url, usr, pwd) passed");
Logger.global.log(Level.FINE, "==============\n\n");
return connection;
voidinternalShutdown(String connectionString, int expectedErrorCode, String expectedSQLState)
internal Shutdown
try {
    DriverManager.getConnection(connectionString);
} catch (SQLException ex) {
    boolean successfullShutdown = expectedErrorCode == ex.getErrorCode()
            && expectedSQLState.equals(ex.getSQLState());
    if (!successfullShutdown) {
        throw ex;
booleanrunSQLExecute(String sql, Map config)
run SQL Execute
try {
    Statement statement = getStatement(config);
    return statement.execute(sql);
} catch (Exception e) {
    throw new RuntimeException("Failed to execute query:" + sql, e);