2

I receive exception when my web project tries to connect database.

Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException Exception Description: Configuration error. Class [com.mysql.jdbc.Driver] not found.at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)

My persistence.xml is like this:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="flashpoll">
<class>entities.Question</class>
<class>entities.Poll</class>
<class>entities.User</class>
<class>entities.Answers</class>
<class>entities.Admin</class>
<properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/flashpoll"/>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
        <property name="javax.persistence.jdbc.password" value="12345"/>
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />
    </properties>
</persistence-unit>
</persistence>

mysql-connector-5.0.8 is also included in the libraries of the project. Any idea why do I still receive this Class [com.mysql.jdbc.Driver] not found error? Thanks for any help.

4

2 回答 2

11

创建 Web 应用程序时,您的库(jar)应放在 WEB-INF/lib 文件夹中,以便被 Web 应用程序服务器(Tomcat、JBoss、GlassFish 等)识别。只需在此文件夹中复制/粘贴您的 mysql 驱动程序和其他第三方库,然后重新部署您的应用程序。

于 2013-10-10T19:22:24.293 回答
0

我只是有同样的问题。因此,您必须进入您的 java 项目,右键单击它,然后转到属性。在库中复制并粘贴您的 mysql_connector_java_bin.jar 作为 jar 文件。例如,您可以在以下位置找到它:“C:\Program Files\NetBeans 8.0.2\ide\modules\ext”。

于 2015-11-30T12:10:23.090 回答