注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 QoS流量的分类和标记
 帮助

Tomcat5.5X连接池(dbcp)


2008-02-24 11:09:31
版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://973007.blog.51cto.com/100031/62943
容器:Tomcat 5.5X
数据库:MySql5.0
  主要涉及几个目录,几个文件,如下
*  以下配置根据自己实际情况修改~
__________________________
1    Tomcat 安装目录/conf下/server.xml
在server.xml中~在<Context>里添加
<Resource auth="Container" name="jdbc/pure" type="javax.sql.DataSource" username="root" password="5200" driverClassName="org.gjt.mm.mysql.Driver" maxIdle="2" maxWait="5000" url="jdbc:mysql://localhost:3306/pure" maxActive="4"/>
 
 
2    Tomcat 安装目录\conf\Catalina\localhost  下新建一个与你工程文件夹一样名字的xml
比如你webapps下的工程名为test,那么就在Tomcat 安装目录\conf\Catalina\localhost  新建一个text.xml ,加入内容:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
 <Resource
      name="jdbc/pure"
      type="javax.sql.DataSource"
      password="5200"
      driverClassName="org.gjt.mm.mysql.Driver"
      maxIdle="2"
      maxWait="5000"
      username="root"
      url="jdbc:mysql://localhost:3306/pure"
      maxActive="4"/>
</Context>
3    项目工程中的web.xml
<resource-ref>
   <description>DB Connection</description>
  <res-ref-name>jdbc/pure</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>
 
__________________________________________
经常报的一些异常说以下
Cannot create JDBC driver of class '' for connect URL 'null'
1  检查驱动放到tomcat 目录/conmm/lib 下没
2  检查server.xml正不正确~或者用了版本不同的配置方法,所以没认到
3  在\conf\Catalina\localhost  新建了xml没~确认一下参数
 
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
 直接确认是不是没有在web.xml加入相应内容
<resource-ref>
   <description>DB Connection</description>
  <res-ref-name>jdbc/pure</res-ref-name>
  <res-type>javax.sql.DataSource</res-type>
  <res-auth>Container</res-auth>
 </resource-ref>
 
 
 

本文出自 “Pure 纯粹--热衷于技术,能自拔而不想” 博客,请务必保留此出处http://973007.blog.51cto.com/100031/62943





    文章评论
 
2008-02-24 20:39:30
学习一下。

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: