This discussion is archived
9 Replies Latest reply: Dec 17, 2006 12:49 PM by dcminter RSS

JavaDB getConnection

807607 Newbie
Currently Being Moderated
Hi! I'm using Java 6 and trying to make a little app for testing the new embedded database (JavaDB). I read somewhere that I don't need to call Class.forName anymore with JDBC 4 and that all that's needed is to get the connection to the database.

However I'm trying with the following code:
    Connection conn;
    public Main() {
        conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:derby:sample");
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
And I get java.sql.SQLException: No suitable driver found for jdbc:derby:sample. What's the correct url for the embedded database?

Thanks a lot!
  • 1. Re: JavaDB getConnection
    807607 Newbie
    Currently Being Moderated
    You need to call
    Class.forName(...)
    above this:
    Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
  • 2. Re: JavaDB getConnection
    807607 Newbie
    Currently Being Moderated
    Ok, my code now reads:
        public Main() {
            
            conn = null;
            try {
                Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
                conn = DriverManager.getConnection("jdbc:derby:sample;create=true");
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (ClassNotFoundException ex){
                ex.printStackTrace();
            }
        }
    But still I get java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
  • 3. Re: JavaDB getConnection
    807607 Newbie
    Currently Being Moderated
    You need to keep derby jar file on the classpath.
  • 4. Re: JavaDB getConnection
    796365 Newbie
    Currently Being Moderated
    From this page
    http://developers.sun.com/prodtech/javadb/

    "Where is Java DB in Sun Products?
    Java DB is currently included with the Java Enterprise System as the Application Server's developer database, and the Portal Server and Service Registry's data stores; it is supported by NetBeans 5.0, Java Studio Enterprise and Java Studio Creator; and, it is included as the out-of-the-box development database in the Sun Java Application Server PE 8.2 and the open community Glassfish implementation. "
  • 5. Re: JavaDB getConnection
    dcminter Newbie
    Currently Being Moderated
    It's in JDK 6 as well now, although I don't think it's in the classpath by default.
  • 6. Re: JavaDB getConnection
    807607 Newbie
    Currently Being Moderated
    I'm sorry but I was under the impression that JavaDB was included with JDK 6 so I wouldn't need to get any extra jars for derby.
  • 7. Re: JavaDB getConnection
    796365 Newbie
    Currently Being Moderated
    dcminter is correct, it now lives in /.../jdk1.6.0/db/... as part of the Java 6 install.

    The javadb page information I posted is out-of-date.

    Message was edited by:
    ChuckBing
  • 8. Re: JavaDB getConnection
    dcminter Newbie
    Currently Being Moderated
    I'm sorry but I was under the impression that JavaDB
    was included with JDK 6 so I wouldn't need to get any
    extra jars for derby.
    You don't need to "get" them, if you're running JDK6, but it does look like you need to explicitly include them in the classpath.
  • 9. Re: JavaDB getConnection
    807607 Newbie
    Currently Being Moderated
    So the reason I can't use JavaDB is the classpath?
    Sorry I posted this before I saw your reply. I'll add it to the classpath

    Message was edited by:
    K-LineD