本文介绍了未找到JDBC Derby驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了JDBC教程,网址为:,并管理构建和创建自己的JDBC数据库,没有太大的麻烦。但是现在当尝试从一个java应用程序连接到数据库时,我收到异常:

I've followed the JDBC tutorial at: http://docs.oracle.com/javase/tutorial/jdbc/basics/gettingstarted.html, and managed to build and create my own JDBC database without too much fuss. However now when trying to connect to the database from a java application I'm receiving the exception:

然后,当尝试手动指定JDBC驱动程序使用:

Then when trying to manually specify the JDBC driver using:

Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

我得到以下异常错误:

java.lang.ClassNotFoundException:org.apache.derby.jdbc.EmbeddedDriver

该驱动程序应该没有加载的问题,因为这是本教程中指定的驱动程序,并没有使用该驱动程序创建数据库的问题。我已经尝试在连接语句的末尾添加属性; create = true,尝试创建一个全新的数据库,但我仍然收到相同的异常错误。

I am positive that that driver should have no issues loading as that is the driver specified in the tutorial and it had no issues creating the database using that driver. I've event tried adding the property " ;create=true" at the end of the connection statement to try and create a brand new database but I still receive the same exception error.

请参阅下面的我的应用程序代码。
任何帮助都是奇妙的:)。

Please see my application code below.Any help at all would be 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();
    }
}


推荐答案

因此,您的错误可能是由以下原因造成的:

So your error can be caused by:

驱动程序未正确加载或您的 URL 格式错误。因此,首先需要确保您的 *。jar 在类路径中。

Driver is not loaded correctly or your URL is malformed. So at first you need to ensure that your *.jar is in classpath. Check it out.

同时尝试将您的 URL 更改为:

Also try to change your URL to:

jdbc:derby://<path>/<databasename>;create=true

create = true 将确保在不存在数据库时创建数据库。

create=true will ensure that db will be created if does not exist.

查看此thead也:

Look at this thead also: SQLException: No suitable driver found for jdbc:derby://localhost:1527

这篇关于未找到JDBC Derby驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 11:13