Java JDBC Connection Create getConnection2()

Here you can find the source of getConnection2()

Description

get Connection

License

Apache License

Declaration

public static Connection getConnection2() 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Main {
    private static String driverName;
    private static String server;
    private static String userName;
    private static String passWord;
    private static ThreadLocal<Connection> tl = new ThreadLocal<Connection>();

    public static Connection getConnection2() {
        Connection conn = tl.get();
        if (conn == null) {
            conn = getConnection();/*  w w  w. j av a 2  s .  c om*/
        }
        return conn;
    }

    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName(driverName);
            conn = DriverManager.getConnection(server, userName, passWord);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }
}

Related

  1. getConnection(String subprotocol, String subname, String user, String password)
  2. getConnection(String url, String username, String password)
  3. getConnection(String url, String userName, String password)
  4. getConnection(String url, String username, String password)
  5. getConnection(String username, String password, String driver, String url)
  6. getConnections(String driver, String url, String user, String pwd)
  7. getConnectionWithTransaction(String dbUrl, String dbUser, String dbPassword)
  8. getDBConnection()
  9. getJdbcOdbcConnection()