java.lang.ClassNotFoundException: 来自 xerial 的 Sample.java 程序中的 org.sqlite.JDBC 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18089952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:18:58  来源:igfitidea点击:

java.lang.ClassNotFoundException: org.sqlite.JDBC error in Sample.java program from xerial

javasqlite

提问by user2646175

I am trying to get Xerial's Sample class to work in Eclipse with sqlite, but I keep getting the error "ClassNotFoundException: org.sqlite.JDBC"

我试图让 Xerial 的 Sample 类在 Eclipse 中使用 sqlite 工作,但我不断收到错误“ClassNotFoundException: org.sqlite.JDBC”

I downloaded the sqlite-jdbc-3.7.2.jar file from https://bitbucket.org/xerial/sqlite-jdbc/downloads. Copied it into the lib folder under my project "database_test" in eclipse. Then right-clicked on the Project->Properties->Java Build Path->Libraries Tab->Add JARs->Select the jar file. I am trying to execute this code from Xerial found here: https://bitbucket.org/xerial/sqlite-jdbc#markdown-header-usage

我从https://bitbucket.org/xerial/sqlite-jdbc/downloads下载了 sqlite-jdbc-3.7.2.jar 文件。将其复制到我在eclipse中的项目“database_test”下的lib文件夹中。然后右键Project->Properties->Java Build Path->Libraries Tab->Add JARs->选择jar文件。我正在尝试从此处找到的 Xerial 执行此代码:https://bitbucket.org/xerial/sqlite-jdbc#markdown-header-usage

// load the sqlite-JDBC driver using the current class loader
Class.forName("org.sqlite.JDBC");

Connection connection = null;
try
{
  // create a database connection
  connection = DriverManager.getConnection("jdbc:sqlite:sample.db");
  Statement statement = connection.createStatement();
  statement.setQueryTimeout(30);  // set timeout to 30 sec.

  statement.executeUpdate("drop table if exists person");
  statement.executeUpdate("create table person (id integer, name string)");
  statement.executeUpdate("insert into person values(1, 'leo')");
  statement.executeUpdate("insert into person values(2, 'yui')");
  ResultSet rs = statement.executeQuery("select * from person");
  while(rs.next())
  {
    // read the result set
    System.out.println("name = " + rs.getString("name"));
    System.out.println("id = " + rs.getInt("id"));
  }
}
catch(SQLException e)
{
  // if the error message is "out of memory", 
  // it probably means no database file is found
  System.err.println(e.getMessage());
}
finally
{
  try
  {
    if(connection != null)
      connection.close();
  }
  catch(SQLException e)
  {
    // connection close failed.
    System.err.println(e);
  }
}

} }

} }

Every site I have been to has said add the jar file to your build path or class path and I believe I have done that, but nothing has solved the problem. Any help would be appreciated. Thanks.

我去过的每个站点都说将 jar 文件添加到您的构建路径或类路径,我相信我已经这样做了,但没有解决问题。任何帮助,将不胜感激。谢谢。

采纳答案by user2646175

Thanks to user phew for the help/ideas.

感谢用户 phew 的帮助/想法。

I missed the obvious command line instructions on Xerial's site for the Sample program. To get the program to run from the command line, I had to copy the JAR file into the same folder as the .java program. Then run the following command:

我错过了 Xerial 网站上有关示例程序的明显命令行说明。为了让程序从命令行运行,我必须将 JAR 文件复制到与 .java 程序相同的文件夹中。然后运行以下命令:

java -classpath ".:sqlite-jdbc-(VERSION).jar" Sample

java -classpath ".:sqlite-jdbc-(VERSION).jar" 示例

回答by Xorsist

One way that worked for me is to go to JRE System Library -> right clik -> build path -> configure build path -> add external jars -> select the jar and compile.

对我有用的一种方法是转到 JRE 系统库 -> 右键单击​​ -> 构建路径 -> 配置构建路径 -> 添加外部 jar -> 选择 jar 并编译。

回答by Chetan Bhagat

first you can download sqlite-jdbc-3.8.11.2and after add jar file in your project

首先你可以下载sqlite-jdbc-3.8.11.2然后在你的项目中添加 jar 文件

Window > Show_view > Package Explorer

step-1: right click on referenced libraries
step-2: select Built path
step-3: configure Built path
step-4: Add External jars file
step-5: add sqlite-jdbc-3.8.11.2
step-6: ok

or second way useful

或第二种方法有用



your project can set the Classpath : Lib/sqlite-jdbc-3.8.11.2.jar

您的项目可以设置类路径:Lib/sqlite-jdbc-3.8.11.2.jar

1)create a folder "Lib" in your project workspace 
2)"Lib" folder paste jar file like "sqlite-jdbc-3.8.11.2.jar"
3)After Double click on your project file i.e. 'MANIFEST.MF'
4)select Runtime(Bottom view panel) 
5)plug-in Classpath(Bottom_right position) to add jar file like "Lib/sqlite-jdbc-3.8.11.2.jar"

this working 100% sure..thanks

回答by Paul

As said before, add the jar File to your Project.

如前所述,将 jar 文件添加到您的项目中。

For Android Studio / IntelliJyou just go this way:

对于Android Studio / IntelliJ,您只需这样做:

File > Project Structure >

文件 > 项目结构 >

enter image description here

在此处输入图片说明

New Module >

新模块 >

enter image description here

在此处输入图片说明

Import .JAR/.AAR Package

导入 .JAR/.AAR 包

enter image description here

在此处输入图片说明

Now select/add your .jar File and let IntelliJ do the rest.

现在选择/添加您的 .jar 文件,让 IntelliJ 完成剩下的工作。

回答by Yash Bansal

All the above solutions works well, when you are dealing with the desktop JAVA Application. In the case of WebAPP Application, following above solutions will not work. Actually it is the issue with your App server, that is you needed to add sqlite-jar under your WEB-INF/lib and then only you will be able to run your webapp successfully.

当您处理桌面 JAVA 应用程序时,上述所有解决方案都运行良好。对于 WebAPP 应用程序,以下解决方案将不起作用。其实这是你的应用服务器的问题,那就是你需要在你的 WEB-INF/lib 下添加 sqlite-jar,然后只有你才能成功运行你的 webapp。

For doing so you can follow below steps:

为此,您可以按照以下步骤操作:

Go to:

去:

Project-> Properties-> Deployment Assembly-> Add-> Archives From File System -> Next -> Add

项目-> 属性-> 部署程序集-> 添加-> 来自文件系统的存档-> 下一步-> 添加

Navigate to the folder where you have your sqlite-jar, select it and hit OK.

导航到您的 sqlite-jar 所在的文件夹,选择它并点击 OK。

Click Finish. OK.

单击完成。好的。

Done, you should be able to run your app now.

完成,您现在应该可以运行您的应用程序了。

Thanks

谢谢

回答by Viraj Singh

Step 1:

Copy sqlite library.

第一步:

复制sqlite库。



Step 2:第 2 步:





将库粘贴到“WebContent/WEB-INF/lib”目录中,您也可以通过在 eclipse 中选择“lib”文件夹并按 Ctrl Ctrl + 来完成V V




Step 3:第 3 步:





重新启动服务器,希望问题应该得到解决