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();
}
}
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';
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.
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.
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With