Here you can find the source of getConnection()
public static Connection getConnection() throws SQLException, ClassNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { private static String url; private static String username; private static String password; private static ThreadLocal<Connection> conList = new ThreadLocal<Connection>(); public static Connection getConnection() throws SQLException, ClassNotFoundException, IOException { Connection con = conList.get(); if (con == null) { try { con = DriverManager.getConnection(url, username, password); conList.set(con);/*from ww w . j av a 2s . c o m*/ } catch (Exception e) { throw new RuntimeException(e); } } return con; } }