/* 获取connection 对象* /
import java.sql.drivermanager; 【程序编程相关:spring + hibernate 数】import java.sql.connection; 【推荐阅读:JSTL使用心得】import oracle.jdbc.driver.oracledriver; 【扩展信息:关于传值和值的引用的问题!】
import java.sql.sqlexception;/**
* @author sfluo * * todo to change the template for this generated type comment go to window - * preferences - java - code style - code templates */public class dbutil {public static connection conn;
public static connection getconnection() {
try {
drivermanager.registerdriver(new oracledriver());
conn = drivermanager.getconnection( "jdbc:oracle:thin:@10.100.143.161:1521:gb02", "gib", "gib"); } catch (sqlexception e) { e.printstacktrace(); }return conn;
}}
利用threadlocal保存connection对象
package conn;import java.sql.connection;
import java.sql.sqlexception;/**
* @author sfluo * * todo to change the template for this generated type comment go to window - * preferences - java - code style - code templates */public class connectionmanage { private static threadlocal currentconn = new threadlocal();public static connection currentconnection() {
... 下一页