I am using one simple code to access the SQLite database from Java application . My code is
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ConnectSQLite { public static void main(String[] args) { Connection connection = null; ResultSet resultSet = null; Statement statement = null; try { Class.forName("org.sqlite.JDBC"); connection = DriverManager.getConnection("jdbc:sqlite:D:\\testdb.db"); statement = connection.createStatement(); resultSet = statement .executeQuery("SELECT EMPNAME FROM EMPLOYEEDETAILS"); while (resultSet.next()) { System.out.println("EMPLOYEE NAME:" + resultSet.getString("EMPNAME")); } } catch (Exception e) { e.printStackTrace(); } finally { try { resultSet.close(); statement.close(); connection.close(); } catch (Exception e) { e.printStackTrace(); } } } }
But this code gives one exception like
java.lang.ClassNotFoundException: org.sqlite.JDBC
How can I slove this,please help me.
To establish a database connection to an SQLite database, you need to create a new instance of the PDO class and pass a connection string to the constructor of the PDO object. Because you store the path to the sqlite database file in the Config class, you just simply use it to construct the connection string.
The SQLiteJDBC package contains both Java classes, as well as native SQLite libraries for Windows, Mac OS X, and Linux. Connecting to an SQLite database: this tutorial shows you how to download SQLiteJDBC driver and connect to an existing SQLite database using JDBC.
You need to have a SQLite JDBC driver in your classpath.
Taro L. Saito (xerial) forked the Zentus project and now maintains it under the name sqlite-jdbc. It bundles the native drivers for major platforms so you don't need to configure them separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With