我在Netbeans中收到此错误:
java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/
Run Code Online (Sandbox Code Playgroud)
这是怎么造成的,我该如何解决?
我遵循了JDBC教程:http://docs.oracle.com/javase/tutorial/jdbc/basics/gettingstarted.html,并设法构建和创建我自己的JDBC数据库,而不用太大惊小怪.但是现在当尝试从java应用程序连接到数据库时,我收到了异常:
java.sql.SQLException:找不到适合jdbc:derby:db目录的驱动程序
然后在尝试使用以下方法手动指定JDBC驱动程序时:
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Run Code Online (Sandbox Code Playgroud)
我收到以下异常错误:
java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver
我很肯定该驱动程序应该没有加载问题,因为这是教程中指定的驱动程序,并且使用该驱动程序创建数据库没有问题.我在事件尝试在连接语句的末尾添加属性"; create = true"以尝试创建一个全新的数据库,但我仍然收到相同的异常错误.
请参阅下面的应用程序代码.任何帮助都会很棒:).
package com.ddg;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class SQLConnect
{
Connection Conn = null;
String URL;
String Username;
String Password;
public SQLConnect()
{
try
{
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
}
catch (ClassNotFoundException e)
{
System.out.println(e.toString());
}
URL = "jdbc:derby:*directory name*";
System.out.println("Created SQL Connect");
}
public void CreateConnection()
{
try
{
Conn = DriverManager.getConnection(URL);
System.out.println("Successfully Connected");
}
catch (SQLException e)
{
System.out.println(e.toString());
}
}
public …Run Code Online (Sandbox Code Playgroud) 我在Netbeans中建立了一个项目,创建了一个脚本,用javadb建立了一个新的数据库.我可以通过gui连接到它 - 显示表内容等,但当我运行一个应用程序时:
EntityManager em = Persistence.createEntityManagerFactory("lab5PU").createEntityManager();
Run Code Online (Sandbox Code Playgroud)
我得到这个很长的例外:
[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)
Run Code Online (Sandbox Code Playgroud)
我可以在服务的驱动程序部分看到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> …Run Code Online (Sandbox Code Playgroud) 我正在使用Eclipse EE Kepler,而我正试图在我的程序中运行derby.我添加到我的构建路径derby.jar,derbyclient.jar但仍然收到以下错误:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver.有人可以帮我解决这个问题吗?