BDCP连接池链接Oracle

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;
	}

}

你可能感兴趣的:(DBCP)