Results 1 to 8 of 8
  1. #1
    dsagud is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Connection to the datebase can't be established

    Connection code:

    Java Code:
    Connection veza = DriverManager.getConnection("jdbc:derby:C://Documents and Settings/$agud/MyDB", "abc", "abc");
    Error:

    Java Code:
    java.sql.SQLException: No suitable driver found for jdbc:derby:C://Documents and Settings/$agud/MyDB
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at java.sql.DriverManager.getConnection(Unknown Source)
    	at paketjdbcprimjer1.GlavnaKlasa.main(GlavnaKlasa.java:20)
    I made the database "MyDB" and add derby to the Eclipse.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Connection to the datebase can't be established

    Did you load and register the derby driver with Class.forName( ... )? Also, read the derby documentation, it is very detailed and explains it all.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    dsagud is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: Connection to the datebase can't be established

    Java Code:
    private static String dbURL = "jdbc:derby:C://Documents and Settings/$agud/MyDB;create=true;user=abc;password=abc";
    	public static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    Java Code:
    Class.forName(driver).newInstance();
    Java Code:
    Connection veza = DriverManager.getConnection(dbURL);
    Error:

    Java Code:
    java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
    	at java.net.URLClassLoader$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    	at java.lang.ClassLoader.loadClass(Unknown Source)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Unknown Source)
    	at paketjdbcprimjer1.GlavnaKlasa.main(GlavnaKlasa.java:22)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Connection to the datebase can't be established

    There's a derby.jar file somewhere on your system (I hope) that contains your driver class; is that jar file on your classpath? The error message indicates it isn't.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    dsagud is offline Member
    Join Date
    Sep 2011
    Posts
    3
    Rep Power
    0

    Default Re: Connection to the datebase can't be established

    Thx Jos.

    I finally find out what I have missed.

    I did copied derby.jar in lib folder in Java project, but I didn't "Add JARs" in Project properties.

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Connection to the datebase can't be established

    Quote Originally Posted by dsagud View Post
    Thx Jos.

    I finally find out what I have missed.

    I did copied derby.jar in lib folder in Java project, but I didn't "Add JARs" in Project properties.
    Good you found it; all classes (and jar files) have to present on the classpath unless you store them in the JRE/lib/ext directory; those IDEs put them on your classpath when you add them to your project.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default Re: Connection to the datebase can't be established

    Quote Originally Posted by JosAH View Post
    Good you found it; all classes (and jar files) have to present on the classpath unless you store them in the JRE/lib/ext directory; those IDEs put them on your classpath when you add them to your project.

    kind regards,

    Jos
    And that's generally considered a bad idea.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,528
    Blog Entries
    7
    Rep Power
    20

    Default Re: Connection to the datebase can't be established

    Quote Originally Posted by Tolls View Post
    And that's generally considered a bad idea.
    True, but notice that I didn't encourage the OP to put the .jar files in there. ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Java.net.socket connection :connection closed
    By veeru541 in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2010, 02:14 AM
  2. Replies: 7
    Last Post: 06-08-2010, 01:36 PM
  3. FTP connection
    By java2010 in forum New To Java
    Replies: 3
    Last Post: 04-19-2010, 09:46 AM
  4. Replies: 7
    Last Post: 10-20-2009, 10:34 AM
  5. no connection
    By even in forum JDBC
    Replies: 15
    Last Post: 01-02-2008, 01:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •