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

ConnectiongetConnection(String url, String userName, String password)
get Connection
return DriverManager.getConnection(url, userName, password);
ConnectiongetConnection(String url, String username, String password)
get Connection
return DriverManager.getConnection(url, username, password);
ConnectiongetConnection(String username, String password, String driver, String url)
get Connection
try {
    Class.forName(driver);
    Properties prop = new Properties();
    prop.setProperty("user", username);
    prop.setProperty("password", password);
    Connection con = DriverManager.getConnection(url, prop);
    return con;
} catch (Exception e) {
...
ConnectiongetConnection2()
get Connection
Connection conn = tl.get();
if (conn == null) {
    conn = getConnection();
return conn;
ConnectiongetConnections(String driver, String url, String user, String pwd)
get Connections
Connection conn = null;
try {
    Properties props = new Properties();
    props.put("remarksReporting", "true");
    props.put("user", user);
    props.put("password", pwd);
    Class.forName(driver);
    conn = DriverManager.getConnection(url, props);
...
ConnectiongetConnectionWithTransaction(String dbUrl, String dbUser, String dbPassword)
get Connection With Transaction
try {
    final Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
    conn.setAutoCommit(false);
    return conn;
} catch (Exception e) {
    throw new RuntimeException("Cannot get connection", e);
ConnectiongetDBConnection()
get DB Connection
if (DB_DRIVER == null) {
    DB_DRIVER = System.getProperty("DB_DRIVER");
    DB_URL = System.getProperty("DB_URL");
    DB_USER = System.getProperty("DB_USER");
    DB_PASSWORD = System.getProperty("DB_PASSWORD");
Connection dbConnection = null;
try {
...
ConnectiongetJdbcOdbcConnection()
get Jdbc Odbc Connection
String odbcDataSourceName = "test1";
String userName = "test1";
String password = "test1";
return getJdbcOdbcConnection(odbcDataSourceName, userName, password);
ConnectiongetNewConnection()
This method establishes a new connection with the database using constants above
Class.forName("org.mariadb.jdbc.Driver");
return DriverManager.getConnection("jdbc:mariadb://localhost:3306/" + DB, DB_USER, DB_PASS);
ConnectiongetPhoenixConnection()
get Phoenix Connection
Class.forName("com.salesforce.phoenix.jdbc.PhoenixDriver");
String connectionURL = "jdbc:phoenix:" + zkQuorum;
Connection r = DriverManager.getConnection(connectionURL);
r.setAutoCommit(true);
return r;