views:

885

answers:

3

Hello,

I am getting a java.sql.SQLException: No suitable driver when I am trying to connect to a database with Java. I am on Mac OS 10.5 using the NetBeans IDE. It seems to be having trouble with the EmbeddedDriver, but I'm not sure what I am missing:

    public class A
    {
        Connection conn = null;

        public A(String URL, String username, String password) throws SQLException
        {    
                try
                {
                     Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
                     conn = DriverManager.getConnection(URL, username, password);
                }
                catch (SQLException sqlException)
                {
                    sqlException.printStackTrace();
                    invalidate();
                }
                catch (ClassNotFoundException classNotFound)
                {
                    classNotFound.printStackTrace();
                    invalidate();
                }
        }
    }
+3  A: 

"No suitable driver" usually means that the URL you've supplied to connect has incorrect syntax. What is your URL?

The server version would have a host and port; I believe the embedded URL should be "jdbc:derby:flixnet", according to these docs: http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html

duffymo
Then I get this:java.sql.SQLException: Database 'flixnet' not found.
Logan Serman
A: 

It is declared as a constant here:

final String DATABASE_URL = "jdbc:derby://localhost:1527/flixnet";

Don't ask about the name... I got this URL by right-clicking the database in NetBeans and then going to Properties -> Database URL.

And I have added the derby.jar and derbyclient.jar files from /Applications/NetBeans/glassfish-v3-prelude/javadb/lib/derby.jar and derbyclient.jar from the same directory.

Logan Serman
The server version would have a host and port; I believe the embedded URL should be "jdbc:derby:flixnet", according to these docs: http://db.apache.org/derby/papers/DerbyTut/embedded_intro.html
duffymo
A: 

Did you add the derbyclient.jar to the "Libraries" folder in your Netbeans project?

zzztimbo