⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connectionutils.java

📁 ecside jsp前途分页的标签 实现ajax 增删改查等
💻 JAVA
字号:
package org.ecside.easydataaccess;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class ConnectionUtils {
	public static final ThreadLocal statementMap = new ThreadLocal();

	public static void initStatementMap(Connection conn){
		String key=String.valueOf(conn);
		Map map=(Map)statementMap.get();
		if (map==null){
			map=Collections.synchronizedMap(new HashMap());
			statementMap.set(map);
		}
		if (map.get(key)==null) {
			map.put(key, new ArrayList());
		}
	}
	
	public static 	void putStatement(Connection conn,Statement statement){
		Map map=(Map)statementMap.get();
		List list=(List)map.get(conn.toString());
		list.add(statement);
	}
	
	public static 	void closeAllStatement(Connection conn){
		Map map=(Map)statementMap.get();
		List list=(List)map.get(conn.toString());
		for (Iterator itor=list.iterator();itor.hasNext();){
			Statement stm=(Statement)itor.next();
			try {
				stm.close();
			} catch (SQLException e) {
			}
		}
	}
	
	public static Statement createStatement(Connection conn) throws SQLException{
		Statement statement=conn.createStatement();
		putStatement(conn,statement);
		return statement;
	}
	
	public static Statement createStatement(Connection conn, int resultSetType, int resultSetConcurrency) throws SQLException{
		Statement statement=conn.createStatement(resultSetType,resultSetConcurrency);
		putStatement(conn,statement);
		return statement;
	}
	
	public static Statement createStatement(Connection conn, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException{
		Statement statement=conn.createStatement(resultSetType,resultSetConcurrency,resultSetHoldability);
		putStatement(conn,statement);
		return statement;
	}

	public static  CallableStatement prepareCall(Connection conn, String sql) throws SQLException {
		CallableStatement statement=conn.prepareCall(sql);
		putStatement(conn,statement);
		return statement;
	}
 
	public static  CallableStatement prepareCall(Connection conn, String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
		CallableStatement statement=conn.prepareCall(sql,resultSetType,resultSetConcurrency);
		putStatement(conn,statement);
		return statement;
	}
 
	public static  CallableStatement prepareCall(Connection conn, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability)  throws SQLException{
		CallableStatement statement= conn.prepareCall(sql,resultSetType,resultSetConcurrency,resultSetHoldability);
		putStatement(conn,statement);
		return statement;
	}

	public static   PreparedStatement prepareStatement(Connection conn, String sql) throws SQLException{
		PreparedStatement statement= conn.prepareStatement(sql);
		putStatement(conn,statement);
		return statement;
	}

	public static  PreparedStatement prepareStatement(Connection conn, String sql, int autoGeneratedKeys) throws SQLException{
		PreparedStatement statement= conn.prepareStatement(sql, autoGeneratedKeys);
		putStatement(conn,statement);
		return statement;
	}

	public static  PreparedStatement prepareStatement(Connection conn, String sql, int[] columnIndexes) throws SQLException{
		PreparedStatement statement= conn.prepareStatement(sql, columnIndexes);
		putStatement(conn,statement);
		return statement;
	}

	public static  PreparedStatement prepareStatement(Connection conn, String sql, int resultSetType, int resultSetConcurrency) throws SQLException{
		PreparedStatement statement= conn.prepareStatement(sql, resultSetType, resultSetConcurrency);
		putStatement(conn,statement);
		return statement;
	}

	public static   PreparedStatement prepareStatement(Connection conn, String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException{
		PreparedStatement statement= conn.prepareStatement(sql, resultSetType, resultSetConcurrency,resultSetHoldability);
		putStatement(conn,statement);
		return statement;
	}

	public static  PreparedStatement prepareStatement(Connection conn, String sql, String[] columnNames) throws SQLException{
		PreparedStatement statement= conn.prepareStatement(sql, columnNames);
		putStatement(conn,statement);
		return statement;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -