connectionkeeper.java
来自「数据库的基本处理类」· Java 代码 · 共 52 行
JAVA
52 行
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 + =
减小字号Ctrl + -
显示快捷键?