📄 connectionkeeper.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 + -