Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JDBC Derby driver not found

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();
    }
}
like image 421
Ice Phoenix Avatar asked Mar 17 '13 09:03

Ice Phoenix


People also ask

How does JDBC connect to Derby?

connect 'jdbc:derby:c:\temp\db\FAQ\db'; If you want to connect to a Derby database which is running in server mode then you can use the following command. connect 'jdbc:derby://localhost:1527/c:\temp\db\FAQ\db;create=true';

How do I install a Derby database in Windows 10?

Download the Derby database software from the Apache website at http://db.apache.org/derby/derby_downloads.html. Extract the files into the directory that you have created for the Derby database. For example: C:\Derby. Set the DERBY_HOME system variable to the location of your Derby installation.

What is Derby in JDBC?

Derby consists of both the database engine and an embedded JDBC driver. Applications use JDBC to interact with a database. Applications running on JDK 1.5 or earlier, must load the driver in order to work with the database. In an embedded environment, loading the driver also starts Derby.


1 Answers

If you have this type of error

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

and you are using netbeans then you have to follow these steps:

  1. right click on library
  2. choose add library option and from the list of libraries choose "Java DB Driver"

enter image description here

like image 160
Mamta Aluria Avatar answered Oct 04 '22 00:10

Mamta Aluria