Hello, I'm using NetBeans 6.7.1, and Derby I'm trying to learn how to write Database applications, and I'm having trouble connecting to my Database. It loads the Derby Driver (EmbeddedDriver), but won't connect to the the Database named test. I looked at tests Properties in NetBeans, and it said that it was using the org.apache.jdbc.derby.ClientDriver. I did create the Database, and give it no username or password. Below is the code that I have. If anybody could help, that would be great =D

package jdb.test;
import java.sql.*;

public class DatabaseTest {

    public static void main(String[] args){
            // Load the EmbeddedDriver class
            System.out.println("Loaded Derby Driver");
        }catch(Exception e){
            System.out.println("Error loading Derby Driver.  Shutting down.");

        // The database located on my computer
        String database = "jdbc:derby://localhost:1527/test";
            // Connect without a username and password
            Connection conn = DriverManager.getConnection(database);
            System.out.println("Connected to "+database);
        }catch(SQLException e){
            System.out.println("Could not connect to "+database);
        System.out.println("You have connect to the selected database.");

This is the error that I get:

java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/test
        at java.sql.DriverManager.getConnection(DriverManager.java:602)
        at java.sql.DriverManager.getConnection(DriverManager.java:207)
        at jdb.test.DatabaseTest.main(DatabaseTest.java:22)

Recommended Answers

All 7 Replies

Your code is loading the EmbeddedDriver class, but using the ClientDriver network url for your connection string. The EmbeddedDriver uses the database name instead of the //servername url.

I tried using "jdbc:derby:test" instead of ""jdbc:derby://localhost:1527/test", but it gave me this error:

(this is the entire output from the execution)

Loaded Derby Driver
java.sql.SQLException: Database 'test' not found.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.handleDBNotFound(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection.<init>(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection30.<init>(Unknown Source)
        at org.apache.derby.impl.jdbc.EmbedConnection40.<init>(Unknown Source)
        at org.apache.derby.jdbc.Driver40.getNewEmbedConnection(Unknown Source)
        at org.apache.derby.jdbc.InternalDriver.connect(Unknown Source)
        at org.apache.derby.jdbc.AutoloadedDriver.connect(Unknown Source)
Could not connect to jdbc:derby:test
        at java.sql.DriverManager.getConnection(DriverManager.java:582)
        at java.sql.DriverManager.getConnection(DriverManager.java:207)
        at jdb.test.DatabaseTest.main(DatabaseTest.java:22)
Caused by: java.sql.SQLException: Database 'test' not found.
        at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
        at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
        ... 15 more

I tried setting the derby.system.home property to the location where I was storing the databases, but that didn't help either. It looks like I'm structuring everything correctly... I'm sorry, I think I'm missing something really obvious >.<

Thank you for all of your help :) If I find anything, I'll post it here.

AHA! I used the create property to create a new Database, and then searched for it using the OS's Search Program. I found the newly created database in the NetBeans project folder. I can not successfully connect to the database. I don't know how to add that new Database to the list of databases that are editable directly through NetBeans.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.