문제

I am trying to use Java DB for app only storage.

Environment Variables:

CLASSPATH:
%JAVA_HOME%\jre\lib;%DERBY_HOME%\lib\derby.jar
DERBY_HOME:
C:\Program Files\Java\jdk1.7.0_25\db
Path:
%DERBY_HOME%\bin

No changes in eclipse configurations was done and i cannot include it to build path(it somehow will be considered as third party library, which is not allowed) When i type "sysinfo" in cmd it tells me Db is instaled and list packages and other info.

Code:

   public class Main {
        private static String dbURL = "jdbc:derby:AssertDB;user=me;password=mine;create=true";
        private static Connection con = null;

    public static void main(String[] args) {
        setDBSystemDir();
        createConnection();
        CookiesTable pTable = new CookiesTable(con);
        try {
            pTable.createTable();
            pTable.populateTable();

        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        // TODO Auto-generated method stub
        // load files
        // parse files to tables
        // retrive SQL statment
        // print result

    }

    private static void setDBSystemDir() {
        // Decide on the db system directory: <userhome>/.addressbook/
        String userHomeDir = System.getProperty("user.home", ".");
        String systemDir = userHomeDir + "/.asertdb";

        // Set the db system directory.
        System.setProperty("derby.system.home", systemDir);
    }

    private static void createConnection() {

        try {
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
            // Get a connection
            con = DriverManager.getConnection(dbURL);
        } catch (Exception except) {
            System.out.println("DRIVER DRROOOOOP");
            except.printStackTrace();
        }
    }

}

Exception:

java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at com.tuto.p4.Main.createConnection(Main.java:44)
    at com.tuto.p4.Main.main(Main.java:13)
Exception in thread "main" java.lang.NullPointerException
    at com.tuto.p4.CookiesTable.createTable(CookiesTable.java:29)
    at com.tuto.p4.Main.main(Main.java:16)
도움이 되었습니까?

해결책

Refering to the documentation there are two things to do in case you get a java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver if you run the SampleApp.

  1. Configure Embedded Derby
  2. Verify Derby

As you said that you checked sysinfo I would try it with adding derby.jar and derbytools.jar even if the tools are optional.

Or you can compare the SampleApp to your App....

다른 팁

Include derbytools.jar, derbyclient.jar as well.

Try putting System.out.println(System.getProperty("java.class.path")); before Class.forName(...).newInstance()

The output must contain a valid path to derby.jar.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top