Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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:

java.sql.SQLException: No suitable driver found for jdbc:derby:db directory

Then when trying to manually specify the JDBC driver using:

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

I get the following exception error:

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

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();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
284 views
Welcome To Ask or Share your Answers For Others

1 Answer

java.sql.SQLException: No suitable driver found for jdbc:derby:db directory

So your error can be caused by:

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.

Also try to change your URL to:

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

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

Update:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...