首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

关于jsp连接MYSQL数据库连接池的使用,该怎么解决

2011-12-31 
关于jsp连接MYSQL数据库连接池的使用请教关于JSP连接MYSQL数据库连接池的配置以及使用方法,本人从书上配置

关于jsp连接MYSQL数据库连接池的使用
请教关于JSP连接MYSQL数据库连接池的配置以及使用方法,本人从书上配置好后,但是在编译时总是找不到类包,虽然我已经在SERVER.xml和WEB。XML下已经配置完,但是具体什么意思也不清楚,书上没有具体说明配置的详细意思,现在请教各位,将本人配置也写在下面
        MYSQL   的数据库名为lianxi   用户名ROOT密码111,在tomcat的ROOT下新建了一个目录panligang
    SERVER.xml添加配置如下
  <Context   path= "/panligang "   docBase= "panligang "   debug= "5 "   reloadable= "true "   crossContext= "true ">    
<Logger   className= "org.apache.catalina.logger.FileLogger "   prefix= "localhost_DBTest_log. "   suffix= ".txt "   timestamp= "true "/>
                    <Resource   name= "jdbc/mysql/lianxi "   auth= "Container "   type= "javax.sql.DataSource "/>  
                    <ResourceParams   name= "jdbc/lianxi ">      
                                      <parameter>
                                                              <name> factory </name>      
                                                              <value> org.apache.commons.dbcp.BasicDataSourceFactory </value>      
                                      </parameter>      

                                                                <!--   Class   name   for   mm.mysql   JDBC   driver   -->    
                                      <parameter>        
                                                                <name> driverClassName </name>            
                                                                <value> com.mysql.jdbc.Driver </value>      
                                      </parameter>  

                                                                <!--   The   JDBC   connection   url   for   connecting   to   your   MySQL   dB.              


                                                                          The   autoReconnect=true   argument   to   the   url   makes   sure   that   the          
                                                                          mm.mysql   JDBC   Driver   will   automatically   reconnect   if   mysqld   closed  
                                                                          the   connection.     mysqld   by   default   closes   idle   connections   after   8   hours.-->    
                                      <parameter>    
                                                                <name> url </name>
                                                                <value> jdbc:mysql://localhost:3306/lianxi?autoReconnect=true </value>
                                      </parameter>  

                                                                <!--   MySQL   dB   username   and   password   for   dB   connections     -->    
                                      <parameter>    
                                                                <name> username </name>      
                                                                <value> root </value>      
                                      </parameter>      

                                      <parameter>      
                                                                <name> password </name>  


                                                                <value> 111 </value>      
                                      </parameter>

                                                                  <!--   Maximum   number   of   dB   connections   in   pool.   Make   sure   you  
                                                                            configure   your   mysqld   max_connections   large   enough   to   handle            
                                                                            all   of   your   db   connections.   Set   to   0   for   no   limit.-->
                                      <parameter>        
                                                                <name> maxActive </name>      
                                                                <value> 100 </value>      
                                      </parameter>    

                                                                  <!--   Maximum   number   of   idle   dB   connections   to   retain   in   pool.  
                                                                            Set   to   0   for   no   limit.   -->    
                                      <parameter>    
                                                                <name> maxIdle </name>


                                                                <value> 30 </value>
                                      </parameter>

                                                                <!--   Maximum   time   to   wait   for   a   dB   connection   to   become   available   in   ms,
                                                                          in   this   example   10   seconds.   An   Exception   is   thrown   if   this   timeout
                                                                          is   exceeded.     Set   to   -1   to   wait   indefinitely.-->      
                                      <parameter>          
                                              <name> maxWait </name>
                                              <value> 10000 </value>    
                                      </parameter>  
                                      <parameter>
                                      <name> removeAbandoned </name>
                                      <value> true </value>
                                      </parameter>
                                      <parameter>
                                      <name> removeAbandonedTimeout </name>
                                      <value> 60 </value>
                                      </parameter>    


                                      <parameter>
                                      <name> logAbandoned </name>
                                      <value> true </value>
                                      </parameter>
                </ResourceParams>
</Context>
在web.xml下添加了如下代码  
<resource-ref>
    <description> MySQL     Datasource     example </description>
    <res-ref-name> jdbc/mysql/lianxi </res-ref-name>
    <res-type> javax.sql.DataSource </res-type>
    <res-auth> Container </res-auth>  
</resource-ref>
  我已经下载了JDBC驱动并且放在   了JDK的LIB下,在TOMCAT的COMMAN的LIB下也同样放了驱动程序,运行别的JAVA   APPLICATION   程序没有   错误,但是就是下面这个程序总出错,
package   sso.common;

import   javax.sql.DataSource;
import   java.sql.SQLException;
import   javax.servlet.ServletContext;
import   java.util.*;
import   javax.servlet.http.*;
import   sso.common.*;
import   javax.naming.*;

public   class   DBUtil   {

  static   String   message= " ";



public   static   DataSource   getPool(String   dbName){
Context   initCtx=null;
              Context   ctx=null;
              DataSource   ds=null;
             
                try{
                    initCtx   =   new   InitialContext();
                   
                        ctx   =   (Context)   initCtx.lookup( "java:comp/env ");
                                                   
                        ds   =   (DataSource)   ctx.lookup(dbName);
                                                     
                      }catch(Exception   e){
                        System.out.println(e.getMessage()+ "找不到数据源 "+dbName);
                        message= "找不到数据源 ";
                        if   (initCtx   ==   null)
                                return   null;


                    }
                 
                    return   ds;
        }
       
        public   static   String   getMessage(){
       
                return   message;
        }  
        }
出错提示package   javax.servelet.http不存在
请各位大虾指教

[解决办法]
检查下是否没有引进servlet-api.jar
[解决办法]
javax.servelet.http是不存在,是不是什么地方把servlet写成了servelet?
[解决办法]
servlet-api.jar

jsp-api.jar
看看是否加入

热点排行