Here you can find the source of getConnection2()
public static Connection getConnection2()
//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; } }