Java JDBC Connection Create getDBConnection()

Here you can find the source of getDBConnection()

Description

get DB Connection

License

Open Source License

Declaration

private static Connection getDBConnection() 

Method Source Code

//package com.java2s;
/*//w  w  w  .j a  v  a 2  s .c  om
 * The MIT License (MIT)
 *
 * Copyright (c) 2011-2016 Broad Institute, Aiden Lab
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */

import java.sql.*;

public class Main {
    private static String DB_DRIVER;
    private static String DB_URL;
    private static String DB_USER;
    private static String DB_PASSWORD;

    private static Connection getDBConnection() {

        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 {

            Class.forName(DB_DRIVER);

        } catch (ClassNotFoundException e) {

            System.out.println(e.getMessage());

        }

        try {

            dbConnection = DriverManager.getConnection(DB_URL, DB_USER,
                    DB_PASSWORD);
            //return dbConnection;

        } catch (SQLException e) {

            System.out.println(e.getMessage());

        }

        return dbConnection;

    }
}

Related

  1. getConnection(String url, String username, String password)
  2. getConnection(String username, String password, String driver, String url)
  3. getConnection2()
  4. getConnections(String driver, String url, String user, String pwd)
  5. getConnectionWithTransaction(String dbUrl, String dbUser, String dbPassword)
  6. getJdbcOdbcConnection()
  7. getNewConnection()
  8. getPhoenixConnection()
  9. getSourceConnection(final Hashtable env)