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

tomcat连接池问题!!
想配置一个简单的连接池,老是报错!
org.apache.tomcat.dbcp.dbcp.SQLNestedException:   Cannot   create   JDBC   driver   of   class   ' '   for   connect   URL   'null '

在网上找了好多资料,多没甚么作用!不知道为什么?只能来这问问!
我创建虚拟目录   /ASP       修改3处配置文件
conf/server.xml  
<GlobalNamingResources> </GlobalNamingResources> 之间添加如下:

<Resource   name= "jdbc/Asp "   type= "javax.sql.DataSource "   password= "timeout "   driverClassName= "net.sourceforge.jtds.jdbc.Driver "   maxIdle= "2 "   maxWait= "5000 "   username= "sa "   url= "jdbc:jtds:sqlserver://127.0.0.1:1433/card;charset=GB2312;SelectMethod=CURSOR "   maxActive= "4 "   />  

conf/Catalina/localhost   下新建   Asp.xml
文件内容:
<Context>
   <Resource   name= "jdbc/Asp "   type= "javax.sql.DataSource "   password= "timeout "   driverClassName= "net.sourceforge.jtds.jdbc.Driver "   maxIdle= "2 "   maxWait= "5000 "   username= "sa "   url= "jdbc:jtds:sqlserver://127.0.0.1:1433/card;charset=GB2312;SelectMethod=CURSOR "   maxActive= "4 "/>  
</Context>

Asp/WEB-INF/web.xml文件 <web-app> </web-app> 之间添加:
  <resource-ref>
    <description> DB   Connection </description>  
    <res-ref-name> jdbc/Asp </res-ref-name>  
    <res-type> javax.sql.DataSource </res-type>  
    <res-auth> Container </res-auth>  
    </resource-ref>


不知道还有甚么地方需要修改!
注:JDBC驱动jtds包,   数据库sql   2000sp4     驱动单独测试没甚么问题!可以连接。
测试程序:
<%
Context   ctx=null;
Connection   cnn=null;
Statement   stmt=null;
ResultSet   rs=null;
try
{
  ctx=new   InitialContext();
  if(ctx==null)
    throw   new   Exception( "没有匹配的环境 ");
  DataSource   ds=(DataSource)ctx.lookup( "java:comp/env/jdbc/Asp ");
  if(ds==null)
    throw   new   Exception( "没有匹配数据库 ");
 
  cnn=ds.getConnection();
  stmt=cnn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  rs=stmt.executeQuery( "select   *   from   area1 ");

 

}
finally
{
  if(rs!=null)
    rs.close();
  if(stmt!=null)
    stmt.close();
  if(cnn!=null)
    cnn.close();
  if(ctx!=null)
    ctx.close();
}
%>

望高手解答!

------解决方案--------------------
conf/Catalina/localhost 下新建 Asp.xml
文件内容:

<?xml version= '1.0 ' encoding= 'utf-8 '?>
<Context crossContext= "true " docBase= "C:/Tomcat 5.0/webapps/asp " path= "/asp " reloadable= "true ">
<ResourceLink name= "jdbc/mysql " global= "jdbc/mysql " type= "javax.sql.DataSource "/>
</Context>
------解决方案--------------------