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

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

I downloaded the sqlite-jdbc-3.7.2.jar file from https://bitbucket.org/xerial/sqlite-jdbc/downloads . I copied it to the lib folder in my project "database_test" in eclipse. Then right-click on the tab "Project"> "Properties"> "Java build path" → "Libraries" → Add JARs-> Select jar file. I am trying to execute this code from Xerial found here: 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 talked about adds a jar file to your build path or class path, and I believe I did it, but nothing solved the problem. Any help would be greatly appreciated. Thanks.

+9
java sqlite sqlite3
source share
7 answers

Thanks to phew for his help / ideas.

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

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

+7
source share

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

+1
source share

first you can download sqlite-jdbc-3.8.11.2 and after adding the jar file to your project

 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 the second method is useful


your project can install Classpath: 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 ie '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 
+1
source share

All of the above solutions work well when you are dealing with a JAVA desktop application. In the case of a WebAPP application, the following solutions will not work. This is actually a problem with your application server, so you need to add sqlite-jar under your WEB-INF / lib, and only then can you successfully launch your web server.

To do this, you can follow these steps:

Switch to:

Project-> Properties-> Deployment Assembly-> Add-> Archives from the file system → Next → Add

Go to the folder where you have sqlite-jar, select it and click OK.

Click Finish. OK

Done, now you can run your application.

thanks

+1
source share

As already mentioned, add the flag file to your project.

For Android Studio / IntelliJ, you just go as follows:

File> Project Structure>

enter image description here

New module>

enter image description here

Import a .JAR / .AAR package

enter image description here

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

0
source share

Step 1:

Copy the sqlite library.


Step 2:

insert the library into the directory 'WebContent / WEB-INF / lib', you can also do this by selecting the 'lib' folder in eclipse and pressing Ctrl + V

Step 3:

Reboot the server and hopefully the problem should be fixed.
0
source share

Here I was late for a couple of years, but all morning I was banging my head about this problem.

Yash Bansal's answer solved my problems: stack overflow

In Eclipse, writing a web application

JAR needs to be added to the server

Project-> Properties-> Deployment Assembly-> Add-> Archives from the file system → Next → Add

Go to the folder where your sqlite-jar is located, select it and click OK.

Thank you, Yash!

0
source share

All Articles