First download the jar package in HTTPS://GITHUB.COM/XERIAL/SQLITE-JDBC
Import Java.sql.connection;import java.sql.drivermanager;import java.sql.resultset;import java.sql.SQLException; Import Java.sql.statement;public class Mainprocess {public static void main (string[] args) {Connection Connection = null;t ry {//Create a database Connectionconnection = drivermanager.getconnection ("jdbc:sqlite:sample.db"); Statement Statement = Connection.createstatement (); Statement.setquerytimeout (30); Set Timeout to $ sec.statement.executeUpdate ("drop table if exists person"), Statement.executeupdate ("CREATE TABLE per Son (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