First download the jar package in HTTPS://GITHUB.COM/XERIAL/SQLITE-JDBC
Importjava.sql.Connection;ImportJava.sql.DriverManager;ImportJava.sql.ResultSet;Importjava.sql.SQLException;Importjava.sql.Statement; Public classmainprocess { Public Static voidMain (string[] args) {Connection Connection=NULL; Try { //Create a database connectionConnection = Drivermanager.getconnection ("jdbc:sqlite:sample.db"); Statement Statement=connection.createstatement (); Statement.setquerytimeout (30);//set Timeout to the 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 setSystem.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 foundSystem.err.println (E.getmessage ()); } finally { Try { if(Connection! =NULL) Connection.close (); } Catch(SQLException e) {//connection close failed.System.err.println (e); } } }}
"Java" Operation SQLite Database