简体   繁体   中英

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. How to install it on 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.jar
  2. Add the jar file to your class path (open Eclipse project properties, there you'll find the build path)
  3. Run your program.

You usually use Maven, Gradle or manual dependency management when using Java. Linux package managers are very limited in java support.

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.

The Eclipse IDE does not recognize the class. 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.

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
  2. in the Eclipse IDE from the left side, right-click on your project and then select properties
  3. on the left menu, choose the Java build path and click Add variable
  4. click Configure variables and then click New
  5. you should name the variable name field as you name it on the Class.forName("org.sqlite.JDBC"); line, that means your variable name is: org.sqlite.JDBC
  6. on the variable path, you should choose your sqlite-jdbc-XXX.jar file

Finally, I got results from the database also in the Eclipse IDE. ‏ ‏ ‏ ‏ ‏‏ ‏ ‏

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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