hncys 发表于 2017-2-2 11:46:58

Tomcat jndi 数据库配置 连接池配置

  在Tomcat 5.5/conf/Catalina/localhost/xxxxx.xml(xxxxx.xml为你自己的web的配置xml文件)中添加resource
  <Resource name="MYSQL"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
password="********"
maxIdle="2"
maxWait="5000"
username="root"
url="jdbc:mysql://localhost:3306/jnestore"
maxActive="10"/>
  以上是tomcat 5.5版本的配置,5.5版本只有这样陪才有效果,以前的版本可以按照paramter的方法添加;
  Resource 一定要包含在<Context ......> </Context> 之间
  在你的web的路近下,WEB-INF中找到web.xml,添加资源映射
  <resource-ref>
<description>connection</description>
<res-ref-name>MYSQL</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
  把mysql的jdbc驱动.jar包放到tomcat的common/lib下去,也可以放到WEB-INF/lib下,
  重新启动tomcat.
  就可以用Context ctx = new InitialContext();
  DataSource ds = (DataSource) ctx.lookup("java:comp/env/MYSQL");
  Connection con = ds.getConnection(); 来连接数据库连接池
页: [1]
查看完整版本: Tomcat jndi 数据库配置 连接池配置