【问题标题】:Class [org.apache.derby.jdbc.ClientDriver] not found. When trying to connect to db找不到类 [org.apache.derby.jdbc.ClientDriver]。尝试连接到数据库时
【发布时间】:2013-03-28 08:36:16
【问题描述】:

我在 Netbeans 中建立了一个项目,创建了一个脚本,用 javadb 创建了一个新数据库。我可以通过 gui 连接到它 - 显示表格内容等,但是当我运行应用程序时:

 EntityManager em = Persistence.createEntityManagerFactory("lab5PU").createEntityManager();

我得到了这个很长的例外:

[EL Info]: 2013-04-05 21:40:45.554--ServerSession(1198260109)--EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Severe]: 2013-04-05 21:40:45.574--ServerSession(1198260109)--Local Exception Stack: 
Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: Exception [EclipseLink-4003] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Configuration error.  Class [org.apache.derby.jdbc.ClientDriver] not found.
Exception Description: Configuration error.  Class [org.apache.derby.jdbc.ClientDriver] not found.
    at org.eclipse.persistence.exceptions.DatabaseException.configurationErrorClassNotFound(DatabaseException.java:82)

我可以在服务的驱动程序部分看到 javadb 驱动程序,所以我不知道错误可能是什么。

编辑:persistance.xml 按要求:

<?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="lab5PU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>lab5.Colleagues</class>
    <properties>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/lab5"/>
      <property name="javax.persistence.jdbc.password" value="mypass"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.user" value="admin"/>
      <property name="eclipselink.ddl-generation" value="create-tables"/>
    </properties>
  </persistence-unit>
</persistence>

【问题讨论】:

  • 你的数据库连接配置在哪里?在persistence.xml?你能展示一下那个配置吗?
  • @PatrykRoszczyniała 按要求添加了 persistence.xml
  • 我是 JEE 的新手,但这个驱动程序 com.mysql.jdbc.Driver 适用于我的应用程序。
  • 您使用的是哪个版本的 NetBeans?
  • 将其更改为您的驱动程序,导致意外的驱动程序错误。

标签: java database netbeans javadb


【解决方案1】:

我认为您遇到的问题是项目的类路径中没有 Derby 驱动程序。

您可以轻松地将 JavaDB 库添加到您的项目中:

  • 右键单击项目
  • 属性 -> 库
  • 添加库 -> JavaDB 驱动程序

这包括项目类路径中的derby.jarderbyclient.jarderbynet.jar

derbyclient.jar 包含您的代码抱怨的类 org.apache.derby.jdbc.ClientDriver

【讨论】:

  • 我没有选择那个库的选项,我已经下载了 derby 库,我应该把它们放在哪里?
  • 抱歉,它不是“Java DB”而是“Java DB 驱动程序”...(在 NetBeans 7.3 中)
猜你喜欢
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-03
  • 2015-05-28
  • 2012-02-18
  • 1970-01-01
相关资源
最近更新 更多