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

📄 connectionkeeper.java

📁 数据库的基本处理类
💻 JAVA
字号:
package com.neu.wrm.common;

import java.sql.Connection;
import java.lang.InheritableThreadLocal;

/*
 * Created on 2005-4-6
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author liuyuguang
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class ConnectionKeeper {
	private static InheritableThreadLocal thread = new InheritableThreadLocal();

	/**
	 * 
	 * @return Returns the myConnection.
	 */

	public static Connection getMyConnection() throws Exception {
		if (Connection.class.isInstance(thread.get()))
			return (Connection) thread.get();
		else {
			System.out.println("返回类型不匹配");

			throw new Exception("can't get connection");

		}
	}

	/**
	 * @param myConnection
	 *            The myConnection to set.
	 */
	public static void setMyConnection(Connection con) {
		clearMyConnection();
		thread.set(con);

	}

	public static void clearMyConnection() {
		thread.set(null);

	}
}

⌨️ 快捷键说明

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