ITPub博客

首页 > 数据库 > > Resin配置数据库连接池

Resin配置数据库连接池

作者:LCR_ 时间:2022-04-12 17:32:27 0 删除 编辑

首先需要将相应的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();

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70000523/viewspace-3143167/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2022-02-22

  • 博文量
    1402
  • 访问量
    14958