随笔 - 9  文章 - 4  trackbacks - 0
<2009年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜

一、在项目中的配置:
             .在WebRoot/META-INF下建context.xml文件,注意必须在该目录下:                  
                  <?xml version="1.0" encoding="UTF-8"?>
                            <Context reloadable="true" crossContext="true">
                               <Resource
                                   name="jdbc/项目名" ---------------必须为项目名,否则会有异常
                                   auth="Container"---------------------该项为不变项
                                   type="javax.sql.DataSource"---------该项为不变项
                                  driverClassName="com.mysql.jdbc.Driver"------------数据库驱动名
                                  url="jdbc:mysql://localhost:3306/haotian?autoReconnect=true"---url
                                  username="root"---------------------------------------用户名
                                  password="root"----------------------------------------密码
                                  maxActive="10"   ----------------------------最大连接数
                                  maxIdle="5"     -------------------------------最大空闲连接数
                                  maxWait="-1"/>   ------------------最大等待毫秒数,-1为无限等待
                            </Context>
               在Tomcat6.0以后就不需要在web.xml中配置了:
                                 <resource-ref>
                                            <description>DB Connection</description>
                                             <res-ref-name>jdbc/blog</res-ref-name>
                                             <res-type>javax.sql.DataSource</res-type>
                                             <res-auth>Container</res-auth>
                                   </resource-ref>


二、配置过程中遇到的异常及解决方法:
      (1)org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
        解决方法:连接池的名字是name="jdbc/项目名"
     
      (2)org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

        解决方法:必须把mysql的驱动包,拷贝到tomcat/lib目录下
   
     (3)javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
         这个异常可能是使用tomcat6版本以下,需要在项目的web.xml配置:
                                        <resource-ref>
                                            <description>DB Connection</description>
                                             <res-ref-name>jdbc/blog</res-ref-name>
                                             <res-type>javax.sql.DataSource</res-type>
                                             <res-auth>Container</res-auth>
                                   </resource-ref>

以上是个人在开发过程中遇到的异常,在参考网友提供解决及个人实践总结所得。

posted on 2009-07-04 21:24 田园风光 阅读(542) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: