简体   繁体   English

流行错误 - org.sqlite.JDBC

[英]Popular error - org.sqlite.JDBC

package aplikacjajava;

import java.sql.*;

public class main
{
  public main( String args[] )
  {
    Connection c = null;
    try {
      Class.forName("org.sqlite.JDBC");
      c = DriverManager.getConnection("jdbc:sqlite:projekt.db");
    } catch ( Exception e ) {
      System.err.println( e.getClass().getName() + ": " + e.getMessage() );
      System.exit(0);
    }
    System.out.println("Opened database successfully");
  }
}

Error:错误:

java.lang.ClassNotFoundException: org.sqlite.JDBC

I know that I'm missing JDBC driver.我知道我缺少 JDBC 驱动程序。 How to install it on Fedora?如何在 Fedora 上安装它?

I don't how to add some "path" and what is this at all.我不知道如何添加一些“路径”以及这是什么。 I need something like step-by-step explanation... This is first time when I met with such a problem.我需要一步一步的解释......这是我第一次遇到这样的问题。

  1. Download the SQLite-jar at http://search.maven.org/remotecontent?filepath=org/xerial/sqlite-jdbc/3.8.10.1/sqlite-jdbc-3.8.10.1.jarhttp://search.maven.org/remotecontent?filepath=org/xerial/sqlite-jdbc/3.8.10.1/sqlite-jdbc-3.8.10.1.jar下载 SQLite-jar
  2. Add the jar file to your class path (open Eclipse project properties, there you'll find the build path)将 jar 文件添加到您的类路径(打开 Eclipse 项目属性,您会在那里找到构建路径)
  3. Run your program.运行你的程序。

You usually use Maven, Gradle or manual dependency management when using Java.在使用 Java 时,您通常使用 Maven、Gradle 或手动依赖管理。 Linux package managers are very limited in java support. Linux 包管理器在 Java 支持方面非常有限。

After I set the classpath from the command prompt, I could use the Database by running java javafile.java , and the database was working fine only from the command prompt.从命令提示符设置类路径后,我可以通过运行java javafile.java来使用数据库,并且数据库只能在命令提示符下正常工作。

The Eclipse IDE does not recognize the class. Eclipse IDE 无法识别该类。 While I tried to add external jar file , the good news was when I defined the classpath as a variable inside the Eclipse IDE, then the issue was solved completely.当我尝试添加external jar file ,好消息是当我将类路径定义为 Eclipse IDE 中的变量时,问题就完全解决了。

I did notice your request and tried to add well-detailed instructions on how to fix that issue.我确实注意到了您的请求,并尝试添加有关如何解决该问题的详细说明。

For also solving this issue, follow the steps below:要解决此问题,请按照以下步骤操作:

  1. Download a sqlite-jdbc-XXX.jar file下载一个sqlite-jdbc-XXX.jar文件
  2. in the Eclipse IDE from the left side, right-click on your project and then select properties在左侧的 Eclipse IDE 中,右键单击您的项目,然后选择properties
  3. on the left menu, choose the Java build path and click Add variable在左侧菜单中,选择Java build path并单击Add variable
  4. click Configure variables and then click New单击Configure variables ,然后单击New
  5. you should name the variable name field as you name it on the Class.forName("org.sqlite.JDBC");您应该像在Class.forName("org.sqlite.JDBC");上命名变量名称字段一样命名它Class.forName("org.sqlite.JDBC"); line, that means your variable name is: org.sqlite.JDBC行,这意味着您的变量名称是: org.sqlite.JDBC
  6. on the variable path, you should choose your sqlite-jdbc-XXX.jar file在变量路径上,您应该选择sqlite-jdbc-XXX.jar文件

Finally, I got results from the database also in the Eclipse IDE.最后,我也从 Eclipse IDE 中的数据库中获得了结果。 ‏ ‏ ‏ ‏ ‏‏ ‏ ‏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM