kwj

走越远,路越艰!

常用链接

统计

最新评论

jdbc连接池的使用

在web.xml添加
<resource-ref id="datasource">
        <description>Database connection</description> 
        <res-ref-name>jdbc/test</res-ref-name> 
        <res-type>javax.sql.DataSource</res-type> 
        <res-auth>Container</res-auth> 
</resource-ref>

ROOT.xml
<Context path="/test"
        reloadable="false" crossContext="true" privileged="true" antiResourceLocking="false"

antiJARLocking="false" debug="0">
    <Resource name="jdbc/test" auth="Container"  type="javax.sql.DataSource" username="root" password="123456"  

driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/test?characterEncoding=utf8"   maxActive="100"  

maxIdle="100" />
</Context>
 
需要的库类:
    commons-dbcp.jar  commons-pool.jar mysql-connector-java-3.1.11-bin.jar
程序编写:
InitialContext ctx=new InitialContext();
DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/test");
conn=ds.getConnection();

posted on 2008-04-01 17:06 木剑 阅读(392) 评论(0)  编辑  收藏 所属分类: java