java.lang.NoClassDefFoundError:org / apache / derby / jdbc / ClientDriver,在构建路径中包含了derbyclient.jar

时间:2018-09-10 05:06:08

标签: java jdbc derby

我在Eclipse中遇到此错误,试图连接到我的数据库。 我看了这些建议:

SQLException: No suitable driver found for jdbc:derby://localhost:1527

JDBC Derby driver not found

但是,它们似乎都建议将derbyclient.jar包含到我的项目的构建路径中。

java.lang.NoClassDefFoundError: org/apache/derby/jdbc/ClientDriver at datasource.DBConnection.getDBConnection(DBConnection.java:38)

我的数据库连接:

private static final String DB_CONNECTION = "jdbc:derby://localhost:1527/database;create=true"; 
private static Connection getDBConnection(){
   try {

        DriverManager.registerDriver(new org.apache.derby.jdbc.ClientDriver());

        Connection dbConnection = DriverManager.getConnection(
                        DB_CONNECTION, DB_USER,DB_PASSWORD);
        return dbConnection;

    } catch (SQLException e) {

        System.out.println(e.getMessage());

    }
    System.out.println("Connection problem");
    return null;

}

0 个答案:

没有答案