Search code examples
javaeclipsemavenderby

Exception using apache derby


I got the following exception using apach derby on Eclipse:

java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbededDriver.at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)


Here is my code:

 private static void createConnection()
    {
        try
        {
            Class.forName("org.apache.derby.jdbc").newInstance();
            //Get a connection
            conn = DriverManager.getConnection(dbURL); 
        }
        catch (Exception except)
        {
            except.printStackTrace();
        }
    }

the maven dependency I used for my maven project is:

<!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <version>10.14.1.0</version>
    <scope>test</scope>
</dependency>

I think my program is not detecting the driver.


Solution

  • Class.forName("org.apache.derby.jdbc")
    

    What you define here seems to be a package, not a class. I'm going with the assumption, that you have org.apache.derby.jdbc.EmbededDriver written there and the classname disappeared when you copy-pasted the code here.

    org.apache.derby.jdbc.EmbededDriver class does not exists, because a missing 'd', it should be org.apache.derby.jdbc.EmbeddedDriver.

    So to correct the code, use

    Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();