首页 > 解决方案 > Eclipse 在类路径中找不到 SQLite JDBC。BuildPath 已经自定义。但为什么?

问题描述

我有一个方法,我想用它创建一个具有 5 个属性的表。但是,如果我想运行 createTable 方法,我会收到错误:java.lang.ClassNotFoundException: org.sqlite.JDBC 但是我已经将 SQLite Jar 添加到 BuildPath 中了吗?这是我的代码:

   public static String createTable() {
      Connection c = null;
      Statement stmt = null;

      try {
         Class.forName("org.sqlite.JDBC");
         c = DriverManager.getConnection("jdbc:sqlite:test.db");
      //   System.out.println("Opened database successfully");

         stmt = c.createStatement();
         String sql = "CREATE TABLE Fahrrad "+ 
                        "(ID INT PRIMARY KEY NOT NULL," +
                        " Standort TEXT NOT NULL, " + 
                        " LeihStatus BOOLEAN NOT NULL, " + 
                        " Modell CHAR(50));"; 



         stmt.executeUpdate(sql);
         stmt.close();
         c.close();

      } catch ( Exception e ) {
         System.err.println( e.getClass().getName() + ": " + e.getMessage() );
         System.exit(0);
      }
      // System.out.println("Table created successfully");




      return "SQL Datenbank mit dem Namen Fahrrad und den Attributen ID, Standort, LeihStatus und Modell erfolgreich angelegt.";

}

这是我项目的构建路径的图片:

为什么即使我将外部 jar 添加到构建路径,我也会收到错误消息?提前致谢。

标签: javasqliteweb-services

解决方案


推荐阅读