首先声明。我用的是tomcat6.0 数据库是mysql 数据库连接正常。
证据是
 我用myeclipse 自带的数据查看器。正常连接能看见表。
程序是
System.out.println("1");
 javax.naming.Context ctx=new javax.naming.InitialContext();
 System.out.println("2");
 
 javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:comp/env/jdbc/bookstore");
 System.out.println("3");
 System.out.println(ds);
 
 con=ds.getConnection();
 System.out.println(con);
抛出的异常是 org.apache.tomcat.dbcp.dbcp.BasicDataSource@125b750
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
1
2
3我这样配置的 连接池
大家给看下servel.xml下面这样写 的
 <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">
         <Context path="/sevelet" docBase="D:\java\sevelet" debug="5" reloadable="true" crossContext="true">   
     <Resource name="jdbc/bookstore"      
        auth="Container"          
        type="javax.sql.DataSource"          
      driverClassName="com.mysql.jdbc.Driver"          
     url="jdbc:mysql://localhost:3306/bookstore"          
      username="root"          
      password="123"          
        maxActive="100"          
       maxIdle="30"          
       maxWait="10000" /> 
       </context>然后在web。xml这样写的
<resource-ref>
    <description>MySQL DataSource</description>
     <res-ref-name>jdbc/bookstore</res-ref-name>
     <res-type>javax.sql.DataSource</res-type>
     <res-auth>Container</res-auth>
</resource-ref>
我研究了好长时间也没弄好。希望能得到大家的帮助。谢谢

解决方案 »

  1.   

    driverClassName="com.mysql.jdbc.Driver"   
      

  2.   

    不是server.xml的问题,
    你没有导入mysql的驱动程序包:mysql-connector-java-5.1.0-bin.jar
    导入到项目里也行,导入到tomcat中也行
      

  3.   

    1.打开context.xml,在Context标签下添加形如下:
       <ResourceLink
      global="jdbc/bookstore" name="jdbc/bookstore"
      type="javax.sql.DataSource"/>
    2.你没有导入mysql的驱动程序包:mysql-connector-java-5.1.0-bin.jar 
      导入到项目里也行,导入到tomcat中也行
      

  4.   

    jar包  放入tomcat6.0/lib里
      

  5.   

    javax.naming.NoInitialContextException: Need to specify class name in environment or system property
    连接池的配置就是像我那样的配置没错。仅仅抛出这异常。后来改了改。琢磨下。因为你的 servlet 类没在web。xml注册的原因。