/** * */Package Com.nyist.sqlitedemo;import Java.sql.connection;import java.sql.drivermanager;import Java.sql.resultset;import Java.sql.sqlexception;import java.sql.Statement;/** * @author Yuchao * * @school application and development of mobile device in Nanyang Institute of Technology Software * * @date June 19, 2014 PM 9:20:48*/ Public classSqlitedemo { Public Static voidMain (string[] args) throws ClassNotFoundException, SQLException {class.forname ("Org.sqlite.JDBC"); Connection Connection=drivermanager.getconnection ("jdbc:sqlite:db/test.db"); Statement Statement=connection.createstatement (); Statement.executeupdate ("Drop Table if exists person"); Statement.executeupdate ("CREATE TABLE person (ID int,name string)"); Statement.executeupdate ("INSERT into person values (1, ' yuchao1 ')"); Statement.executeupdate ("INSERT into person values (2, ' Yuchao2 ')"); Statement.executeupdate ("INSERT into person values (3, ' Yuchao3 ')"); ResultSet RS=statement.executequery ("SELECT * from person"); while(Rs.next ()) {System. out. println ("id=>"+rs.getint ("ID")+",name=>"+rs.getstring ("name")); } statement.close (); Connection.close (); }}
Operation Result:
id=>1,name=>yuchao1id=2,name=>yuchao2id=3, name= >yuchao3