Resin配置数据库连接池

本文介绍了如何在Resin应用服务器上配置数据库连接池,以连接到MySQL数据库。首先,需要将MySQL的JDBC驱动放入Resin的lib目录。接着,在resin.conf文件中配置连接池参数,包括JNDI名、URL、用户名和密码。然后,在web.xml中声明资源引用。最后,代码中可以通过JNDI查找获取数据库连接。

首先需要将相应的JDBC驱动放在Resin主目录下的lib目录下
1
resin.conf文件中加入(sample)
<database>
        <jndi-name>jdbc/mysql</jndi-name>
        <driver type="org.gjt.mm.mysql.Driver">
         <url>jdbc:mysql://localhost:3306/mh</url>
         <user>mh81</user>
         <password>mh81</password>
        </driver>
        <prepared-statement-cache-size>8</prepared-statement-cache-size>
        <max-connections>20</max-connections>
        <max-idle-time>30s</max-idle-time>
</database>
2,web.xml
中加入

<resource-ref>
   <description>jdbc/mysql</description>
   <res-ref-name>jdbc/mysql</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>
3,
代码中如何通过连接池获得数据库连接?
Context env = new InitialContext();
DataSource pool = (DataSource) env.lookup("java:comp/env/jdbc/mysql");
if (pool == null) {
    throw new Exception (dataSource + " is unknown datasource!");
}

conn = pool.getConnection();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值