Cannot load JDBC driver class 'com.mysql.jdbc.Driver'

我首先是在MyEclipse中将MySQL的jar包导入

其次,在Tomcat的Server.xml配置文件中设置如下:
<?xml version="1.0" encoding="UTF-8"?>
<Server>
  <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <GlobalNamingResources>
    <Environment
      name="simpleValue"
      type="java.lang.Integer"
      value="30"/>
    <Resource
      auth="Container"
      description="User database that can be updated and saved"
      name="UserDatabase"
      type="org.apache.catalina.UserDatabase"
      pathname="conf/tomcat-users.xml"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
    <Resource
      name="jdbc/mysql"
      type="javax.sql.DataSource"
      password="123456"
      driverClassName="com.mysql.jdbc.Driver"
      maxIdle="40"
      maxWait="5000"
      username="root"
      url="jdbc:mysql://localhost:3306/db_shopping"
      maxActive="40"/>
  </GlobalNamingResources>
  <Service
      name="Catalina">
    <Connector
        port="8080"
        redirectPort="8443"
        minSpareThreads="25"
        connectionTimeout="20000"
        maxSpareThreads="75"
        maxThreads="150">
    </Connector>
    <Connector
        port="8009"
        redirectPort="8443"
        protocol="AJP/1.3">
    </Connector>
    <Engine
        defaultHost="localhost"
        name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
      <Host
          appBase="webapps"
          name="localhost">
      </Host>
    </Engine>
  </Service>
</Server>

再次,在WEB-INF下的web.xml配置如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<resource-ref>
   <description>mysqlDB Connection</description>
   <res-ref-name>jdbc/mysql</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
</resource-ref>
</web-app>
接着,在META-INF目录下新建context.xml文件,
<?xml version="1.0" encoding="UTF-8"?>
<Context>
   <ResourceLink
   name="jdbc/mysql"
   global="jdbc/mysql"
   type="jdbc.sql.DataSource"
   />
</Context>
最后,在WebRoot下新建测试数据库连接池文件:MySQLDSTest.jsp
在浏览器中键入地址:http://localhost:8080/TestLink/MySQLDSTest.jsp

 

 

解决方法:一开始以为将链接数据库的jar包导入MyEclipse的目录下就可以了,现在才知道还要将jar包放到tomcat共享目录lib

里面。重启ok

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值