1. TOMCAT_HOME/conf/context.xml的<Context>标签下添加如下内容:
2. WEB-INF/web.xml中添加如下内容:
3. Web应用中访问JNDI DataSource
<Resource name="jdbc/txazo" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/txazo"/>
2. WEB-INF/web.xml中添加如下内容:
<resource-ref>
<res-ref-name>jdbc/txazo</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3. Web应用中访问JNDI DataSource
InitialContext context = new InitialContext();
DataSource dataSource = (DataSource) context.
lookup("java:comp/env/jdbc/txazo");
Connection connection = dataSource.getConnection();
本文详细介绍如何在Tomcat服务器中配置MySQL数据库连接池。通过修改context.xml和web.xml文件,实现Web应用对数据库资源的有效管理和使用。

500

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



