BDCP连接池链接Oracle

来源:互联网 发布:多空指标优化 编辑:程序博客网 时间:2024/05/25 16:12
import java.io.IOException;import java.io.InputStream;import java.sql.Connection;import java.util.Properties;import javax.sql.DataSource;import org.apache.commons.dbcp.BasicDataSourceFactory;import org.apache.commons.dbcp.ConnectionFactory;/** * @author 廖滨 2014-8-1 */public class ConnFactory {private static ThreadLocal<Connection> connThread = new ThreadLocal<Connection>();private static Properties pro = new Properties();static {try {InputStream is = ConnectionFactory.class.getResourceAsStream("jdbc.properties");pro.load(is);is.close();} catch (IOException e) {e.printStackTrace();}}public static Connection getConnection() {Connection conn = connThread.get();if (conn == null) {try {DataSource ds = BasicDataSourceFactory.createDataSource(pro);conn = ds.getConnection();connThread.set(conn);} catch (Exception e) {e.printStackTrace();}}return conn;}}

0 0
原创粉丝点击