659441806 发表于 2017-1-17 07:21:58

Tomcat JDNI Datasource

1. TOMCAT_HOME/conf/context.xml的<Context>标签下添加如下内容:

<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();
页: [1]
查看完整版本: Tomcat JDNI Datasource