Download Java package: Sqlite-jdbc-3.7.2.jar, put in the Java project directory Lib
The following code example:
Import java.sql.*; import Org.sqlite.JDBC;/** This is a very simple SQLite Java program, * The program to create a database, create a table, and then insert data, * Finally read out the data display*/ Public classSqlitetest { Public Static voidMain (string[] args) {Try { //connect to SQLite's JDBCClass.forName ("Org.sqlite.JDBC"); //Create a connection to the database name Lincj.db if it does not exist in the current directoryConnection conn = Drivermanager.getconnection ("jdbc:sqlite:lincj.db"); //Connection conn = Drivermanager.getconnection ("Jdbc:sqlite:path (path)/lincj.db");Statement stat =conn.createstatement (); Stat.executeupdate ("CREATE TABLE table1 (name varchar (UP), age int);");//Create a table, two columnsStat.executeupdate ("INSERT INTO table1 values (' AA ', +);");//Inserting DataStat.executeupdate ("INSERT INTO table1 values (' BB ', +);" ); Stat.executeupdate ("INSERT INTO table1 values (' cc ', +);" ); ResultSet RS= Stat.executequery ("select * FROM table1;");//Querying Data while(Rs.next ()) {//Print the data you have queriedSystem. out. Print ("name ="+ rs.getstring ("name") +" ");//Column Properties OneSystem. out. println ("Age ="+ rs.getstring (" Age"));//Column Properties Two} rs.close (); Conn.close (); //to end a connection to a database } Catch(Exception e) {e.printstacktrace (); } }}
Java Connection to SQLite database