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

5890

被折叠的 条评论
为什么被折叠?



