tomcat的conf目录下的context.xml的配置如下
<Context reloadable="true">    <!-- Default set of monitored resources -->    <WatchedResource>WEB-INF/web.xml</WatchedResource> <Resource name="jdbc/mysql" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="root" password="214845"
driverClassName="com.mysql.jdbc.Driver" url=="jdbc:mysql://localhost:3306/txmusic"/>
</Context>mysql的驱动包在工程的lib和tomcat的lib下都有,
jsp页面本来用JDBC的传统模式连入数据库,没问题
现在换成     Context context=new InitialContext();
             DataSource ds=(DataSource)context.lookup("java:/comp/env/jdbc/mysql");
             conn=ds.getConnection();就不行了,运行web就显示org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class '
请高手指点,非常感谢
conn=ds.getConnection();

解决方案 »

  1.   

    web.xml里需要配置resource-ref。你这个应该没配置
      

  2.   

    那请问resource-ref怎么配置的呢?谢谢
      

  3.   

    老大,看看tomcat自带的文档吧,什么都指着别人告诉你进步太慢了。
    http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
    web.xml configuration
      

  4.   


    测试项目中:
    在<web-app></web-app>这对元素中加入如下内容:
    <resource-ref>
          <description>DB Connection</description>
          <res-ref-name>jdbc/mysql</res-ref-name>
          <res-type>javax.sql.DataSource</res-type>
          <res-auth>Container</res-auth>
    </resource-ref>
      

  5.   

    配置好了,可是还是不行啊,我的tomcat是6.0的
      

  6.   

    context.xml有了,把您的web.xml粘贴出来看看?web。xml里的res-ref-name要求和Resource name=完全一样,有空格等都不行。
      

  7.   

    mysql的驱动包在工程的lib和tomcat的lib下都有,
    jsp页面本来用JDBC的传统模式连入数据库,没问题
    现在换成    Context context=new InitialContext();
                DataSource ds=(DataSource)context.lookup("java:/comp/env/jdbc/mysql");
                conn=ds.getConnection();就不行了,运行web就显示org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot load JDBC driver class '
    请高手指点,非常感谢红色字体的你写错了。应该为:ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/mysql");