1,写配置文件自动获取连接
在tomcat或者项目的context.xml文件中配置
< Resource auth=“Container”
driverClassName=“oracle.jdbc.driver.OracleDriver”
maxActive=“10” maxIdle=“5” maxWait=“50000”
name=“jdbc/hrs” password=“123456”
type=“javax.sql.DataSource”
url=“jdbc:oracle:thin:@localhost:1521:orcl”
username=“scott”/>
源 管理方式:container容器
驱动类的名字
最大活动连接 150 最大空闲连接,超过就将其他的关闭,吗 最大等待时间秒强制收回连接
数据库密码
数据源类型
oracle的连接字符串
数据库的用户
2项目UTIL工具包中
//连接池——获取连接
public static Connection getConnByPool() throws Exception {
Context context = new InitialContext();
//数据源
DataSource dataSource = (DataSource)context.lookup(“java:comp/env/jdbc/hrs”);
return dataSource.getConnection();
}