Search code examples
javaeclipsederby

Derby and eclipse. "Can't find main" exception. How to add Derby to configuration classpath?


I'm trying to install derby on eclipse according to this guide

My $CLASSPATH :

/opt/Apache/db-derby-10.10.1.1-bin/lib/derby.jar:/opt/Apache/db-derby-10.10.1.1-bin/lib/derbytools.jar

I've also added it to Java build path via project properties. Now whenever i run my program, it says:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/derby/impl/tools/sysinfo/Main
Caused by: java.lang.ClassNotFoundException: org.apache.derby.impl.tools.sysinfo.Main

Any solutions? My code: import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;

import java.util.ArrayList; import java.util.Properties;

public class Sample2 {

    public static void main(String[] args) {
        System.out.println("POOP");
        new Sample2().go(args);
        System.out.println("SimpleApp finished");


    }
    void go(String[] args){
        Connection conn = null;
        ArrayList statements = new ArrayList(); 
        PreparedStatement psInsert = null;
        PreparedStatement psUpdate = null;
        Statement s = null;
        ResultSet rs = null;
        String dbName = "Lab4DB";
        try {
            conn = DriverManager.getConnection(protocol + dbName);
            System.out.println("Connected to and created database " + dbName);
            conn.setAutoCommit(false);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    private String framework = "embedded";
    private String driver = "org.apache.derby.jdbc.EmbeddedDriver";
    private String protocol = "jdbc:derby:";
}

enter image description here


Solution

  • right click on your project run as > run dialog > class path tab then add derby.jar , derbynet.jar and derbyclient.jar by clicking on add external jar

    those three jar file you can find them in the folder downloaded from apatche DB