日期:2014-05-18  浏览次数:20704 次

高分;关于数据库连接池的问题
环境:Tomcat5.0.25   +   jdk1.4+   mysql+Winxp
  首先在http://localhost/admin   创建数据源  
写了个jsp测试
<!doctype   html   public   "-//w3c//dtd   html   4.0   transitional//en "  
"http://www.w3.org/TR/REC-html40/strict.dtd ">  
<%@   page   import= "java.sql.* "%>  
<%@   page   import= "javax.sql.* "%>  
<%@   page   import= "javax.naming.* "%>  
<%@   page   session= "false "   %>  
<%@   page   contentType= "text/html;   charset=gb2312 "   %>

<html>  
<body>  
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">  
<title> </title>  
<%  
    DataSource   ds   =   null;  
    try{  
    InitialContext   ctx=new   InitialContext();  
    ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/mysql ");  
    Connection   conn   =   ds.getConnection();  
    Statement   stmt   =   conn.createStatement();  
    String   strSql   =   "   select   *   from   student ";  
    ResultSet   rs   =   stmt.executeQuery(strSql);  
    while(rs.next()){  
          out.print(rs.getString(1));                                    
        }  
    out.print( "over ");  
    }  
    catch(Exception   ex){  
            out.print( "Error   occur: "+ex.getMessage());  
            ex.printStackTrace();  
    }  
%>  
 
</body>  
</html>  
但是报错如下;Error   occur:Cannot   create   JDBC   driver   of   class   ' '   for   connect   URL   'null '  
很郁闷。高手看看是怎么回事。谢谢   !




------解决方案--------------------
这是我用的,没问题,你试一下
首先:在tomcat目录下的conf目录中建立路径Catalina\localhost,在新建的目录下建立xml文件,注意:名称最好和工程名相同。在里面加入如下内容
<?xml version= "1.0 " encoding= "UTF-8 "?>
<Context displayName= "MessageBoard " docBase= "MessageBoard " path= "/MessageBoard " workDir= "work\Catalina\localhost\Messageboard ">
<Resource auth= "Container " name= "MessageBoard/jdbc/Data " type= "javax.sql.DataSource "> </Resource>
<ResourceParams name= "MessageBoard/jdbc/Data ">
<parameter>
<name> factory </name>
<value> org.apache.commons.dbcp.BasicDataSourceFactory </value>
</parameter>

<parameter>
<name> maxActive </name>
<value> 100 </value>
</parameter>

<parameter>
<name> maxIdle </name>
<value> 30 <