org.apache.tomcat.dbcp.dbcp.SQLNestedException:无法创建类''

时间:2014-10-13 08:40:21

标签: java tomcat jpa datasource

我正在Eclipse Kepler上使用JPA 2.1EclipseLink 2.5Struts 1.3进行项目并部署在Tomcat 7.0上。我创建了一个名为JPADataSource的项目。在这些条件下,我的项目工作正常。然而,当我将DataSources(MySQL)添加到项目中时,它不再起作用了。当我尝试运行代码时,我收到此错误:

javax.persistence.PersistenceException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://localhost:3306/playlist?autoReconnect=true'

我在代码中设置了所有内容。这是我的context.xml(置于/JPADataSource/WebContent/META-INF/):

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/JPADataSource">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
  <ResourceLink
    global="jdbc/playlist"
    name="jdbc/playlist"
    type="javax.sql.DataSource">
  </ResourceLink>    
</Context>

这是我的persistance.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="JPADataSource" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <non-jta-data-source>java:comp/env/jdbc/playlist</non-jta-data-source>  
        <class>model.Singer</class>
        <class>model.Song</class>
        <class>model.User</class>
        <class>model.UserPlaylist</class>
    </persistence-unit>
</persistence>

最后,这是我在<GlobalNamingResources>server.xml下插入的(放在/ server / Tomcat v7.0 Server in localhost-config /中):

<Resource auth="Container" driverClass="com.mysql.jdbc.Driver" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/playlist" password="root" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/playlist?autoReconnect=true" username="root"/>

我做错了什么?或者,我错过了什么/错位?

任何帮助都是相关的。

1 个答案:

答案 0 :(得分:1)

使用"driverClassName" 属性而不是"driverClass"。我希望它能解决您的疑问。