之后,我试图手动指定JDBC驱动程序,使用的方法是:java.sql.SQLException: No suitable driver found for jdbc:derby:db directory
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
我收到以下异常错误:
java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
我确定该驱动程序不应该出现加载问题,因为该驱动程序在教程中指定,并且在使用该驱动程序创建数据库时没有任何问题。我甚至尝试在连接语句的末尾添加属性" ;create=true"以创建全新的数据库,但仍然收到相同的异常错误。
请参见下面的应用程序代码。 任何帮助都将是fantastic :).
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 void CloseConnection()
{
try
{
this.Conn.close();
System.out.println("Connection successfully closed");
}
catch (SQLException e)
{
System.out.println(e.toString());
}
}
public static void main(String args[])
{
SQLConnect sql = new SQLConnect();
sql.CreateConnection();
sql.CloseConnection();
}
}
"jdbc:derby:" + dbName + ";create=true"
吗? - longhua