概念:在内存中开辟一块空间,存放多个数据库连接对象conn
目的:在高频率访问数据库时,使用数据库连接池可以降低服务器系统压力,提升程序运行效率。active状态:当前连接对象被应用程序使用中
Idle状态:空闲状态
实现JDBC tomcat pool
这个是tomcat服务器启动才会生效的数据库连接池
1.META-INF下context.xml【context.xml Tomcat的那个目录里面有】
<?xml version="1.0" encoding="UTF-8"?>
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/***"
username="root"
password="root"
maxActive="50"
maxIdle="30"
name="test"
auth="Container"
maxWait="10000"
type="javax.sql.DataSource"
2.test类
1.Context c = new InitialContext();naming包下
2.DateSource ds= (DateSource)c.lookup("java:comp/env/test")固定写法,test是上面xml文件的
name
3.Connection conn = ds.getConnection();//获取连接对象