随笔-0  评论-5  文章-26  trackbacks-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();

posted on 2009-05-13 13:24 L.J. 阅读(419) 评论(0)  编辑  收藏 所属分类: Web

只有注册用户登录后才能发表评论。


网站导航: