java.sql.SQLException:未找到合适的驱动程序jdbc:derby

java.sql.SQLException:未找到合适的驱动程序jdbc:derby,java,jdbc,derby,Java,Jdbc,Derby,我在项目中创建数据库时遇到问题。我在other中读到,我需要在代码中包含以下内容: Class.forName("org.apache.derby.jdbc.ClientDriver"); 我就这样做了: private static EntityManagerFactory factory; public static Connection getConnection() { try { Class.forName("org.apache.derby.jdbc

我在项目中创建数据库时遇到问题。我在other中读到,我需要在代码中包含以下内容:

Class.forName("org.apache.derby.jdbc.ClientDriver");
我就这样做了:

private static EntityManagerFactory factory;
 public static Connection getConnection() {
      try  {
        Class.forName("org.apache.derby.jdbc.ClientDriver");
        factory = Persistence.createEntityManagerFactory("Zadanie_3PU");
        EntityManager em = factory.createEntityManager();
        Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/iab;create=true", "", "");
        return con;
      }
      catch(Exception ex) {
          System.out.println("Database.getConnection() Error -->" + ex.getMessage());
          return null;
      }
  }
我还确保在类路径中加载了正确的驱动程序:

我还确保我的
persistence.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="Zadanie_3PU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>model.User</class>
    <class>model.Email</class>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/iab;create=true"/>
      <property name="javax.persistence.jdbc.user" value=""/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
    </properties>
  </persistence-unit>
</persistence>

我做错了什么?

你获得连接的方式有点奇怪(为什么你要创建一个
EntityManager
,什么都不做,然后创建一个新的连接?),但除此之外,我没有看到任何明显的错误。请在你的问题中包含完整的例外情况:
Info:   Database.getConnection() Error -->Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/iab;create=true
Error Code: 0