Here you can find the source of getConnection()
public static Connection getConnection()
//package com.java2s; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { public static final String url = "jdbc:mysql://127.0.0.1/myapp"; public static final String user = "hyjapp"; public static final String password = "123"; public static final ThreadLocal<Connection> session = new ThreadLocal<Connection>(); public static Connection getConnection() { Connection conn = session.get(); if (conn == null) { try { conn = DriverManager.getConnection(url, user, password); conn.setAutoCommit(false); session.set(conn);//from www . j av a 2 s. c o m } catch (SQLException e) { e.printStackTrace(); } } return conn; } }