Results 1 to 8 of 8
  1. #1
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default problem with java derby

    Hi im new to java DB(derby).I installed java db recently.I have set the classpath to derby.jar and derbytools.jar ,which has to be done for driver loading.
    here's the sample code i tried with java DB
    Java Code:
    package test;
    import java.sql.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    /**
     *
     * @author SRIDARSHAN
     */
    public class Main {
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            try {
                // TODO code application logic here
                Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
            try {
                Connection con = DriverManager.getConnection("jdbc:derby:testDB", "test", "test");
                System.out.println("success");
            } catch (SQLException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
    }
    but i'm getting a error as
    Java Code:
    Jun 26, 2010 11:12:15 AM test.Main main
    SEVERE: null
    java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
            at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Class.java:169)
            at test.Main.main(Main.java:22)
    help needed here fellas :(

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

    Default

    You didn't set your classpath correctly; it should contain the full (or relative) path to derby.jar (including the file name); you don't need that other .jar file. Also, since you don't have your database yet you should append ";create=true" to your URL.

    A dirty testing workaround is to put the derby.jar file in your lib/ext directory of your JRE so it will always be found, but don't put your application in production that way.

    kind regards,

    Jos

  3. #3
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    First of all i'm using netbeans 6.8,
    and i did set the classpath correctly,secondly i have created the database in netbeans,but when i ran the same program in command prompt class.forname() got executed,but there were errors with connection

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

    Default

    Quote Originally Posted by sridarshan View Post
    First of all i'm using netbeans 6.8,
    and i did set the classpath correctly,secondly i have created the database in netbeans,but when i ran the same program in command prompt class.forname() got executed,but there were errors with connection
    Well, if you say your classpath value is correct but the Exception stack trace says it isn't, I don't want to be part of that arguement. Did you append your URL with the command ";create=true" and did you set the property "derby.system.home"? Read the ample documentation that comes with the JavaDB/Derby distribution.

    kind regards,

    Jos

  5. #5
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    thanks for reply,
    maybe i'm wrong,how do i check i set classpath(just to verify i did i right)?
    and it gives that error only in netbeans,but the same program in cmd prompt gave this eror
    Java Code:
    java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/
    testDB
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at test.main(test.java:19)

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

    Default

    Quote Originally Posted by sridarshan View Post
    thanks for reply,
    maybe i'm wrong,how do i check i set classpath(just to verify i did i right)?
    and it gives that error only in netbeans,but the same program in cmd prompt gave this eror
    Java Code:
    java.sql.SQLException: No suitable driver found for jdbc:derby://localhost:1527/
    testDB
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at test.main(test.java:19)
    I don't know NetBeans so I can't help you there, but what is that hostname and port number doing there? I thought you were using the embedded driver? Also, is your database created yet, i.e. did you put ";create=true" at the end of your URL? (it doesn't do anything if your database is already created). And again, did you set the "derby.system.home" property? Otherwise Derby doesn't know where to look for your database files.

    kind regards,

    Jos

  7. #7
    sridarshan is offline Member
    Join Date
    Jun 2010
    Posts
    9
    Rep Power
    0

    Default

    how do set system.derby.home?

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

    Default

    Quote Originally Posted by sridarshan View Post
    how do set system.derby.home?
    It's all in the documentation, but you don't want to read: set it in your system properties (look at the method System.getProperties()) before you start your Derby database driver.

    kind regards,

    Jos

Similar Threads

  1. derby DB problem
    By edi.gotieb in forum Forum Lobby
    Replies: 8
    Last Post: 05-17-2010, 12:45 PM
  2. Replies: 1
    Last Post: 05-11-2010, 10:31 AM
  3. need some derby tips:
    By kulangotski in forum Advanced Java
    Replies: 4
    Last Post: 03-09-2009, 05:09 PM
  4. using if in derby
    By suhaib1thariq in forum JDBC
    Replies: 0
    Last Post: 01-25-2009, 04:46 AM
  5. Is there a problem with Derby?
    By orion_mcl in forum Advanced Java
    Replies: 0
    Last Post: 08-10-2007, 04:35 AM

Posting Permissions

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