package day0829;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
public class DBCPUtils {
//定义一个静态的连接池对象
static BasicDataSource bd = new BasicDataSource();
//读取配置文件,设置连接池信息
static{
Properties properties = new Properties();
try {
properties.load(new FileReader("configdb.txt"));
String url = properties.getProperty("url");
String username = properties.getProperty("username");
String password = properties.getProperty("password");
bd.setUrl(url);
bd.setUsername(username);
bd.setPassword(password);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//返回一个连接池对象
public static DataSource getDataSource(){
return bd;
}
}