1.server.xml中配置主机应用上下文
<!--
debug="5" reloadable="true" crossContext="true">
maxActive="100" maxIdle="30" maxWait="10000"
username="pc" password="pc" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/petclinic?autoReconnect=true"/>
-->
2.$catalina_home/conf/ 【Catalina引擎】/【主机】/虚拟路径名.xml
<?xml version="1.0" encoding="UTF-8" ?>
name="jdbc/petclinicMYSQL"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
removeAbandoned="true"
logAbandoned="true"
removeAbandonedTimeout="60"
password="pc"
maxIdle="10"
maxWait="5000"
username="pc"
url="jdbc:mysql://localhost:3306/petclinic?autoReconnect=true"
maxActive="50"/>
3. /META-INF/context.xml
<?xml version="1.0" encoding="UTF-8" ?>
name="jdbc/petclinicMYSQL"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
removeAbandoned="true"
logAbandoned="true"
removeAbandonedTimeout="60"
password="pc"
maxIdle="10"
maxWait="5000"
username="pc"
url="jdbc:mysql://localhost:3306/petclinic?autoReconnect=true"
maxActive="50"/>
4.web.xml
<!--
- Reference to PetClinic database.
- Only needed if not using a local DataSource but a JNDI one instead.
-->
<!-- -->
设置资源引用,注意JNDI查找树,资源类型,认证方式等
jdbc/petclinicMYSQL
javax.sql.DataSource
Container
5.应用程序中使用JNDI进行DataSource查找
<!-- JNDI DataSource for J2EE environments -->
<!--
java:comp/env/jdbc/petclinicMYSQL
-->
Context ctx=new InitialContext();
Context envContext = (Context)ctx.lookup("java:/comp/env"); --先查找根树
DataSource ds = (DataSource)envContext.lookup("jdbc/mysqlDS");--查找节点
Connection conn = ds.getConnection(); --获取连接
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9194732/viewspace-914998/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9194732/viewspace-914998/