sqlite-use in Java sqlite-2
Importjava.sql.*; Importorg.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*/publicclass testsqlite{publicstaticvoid Main (string[] args) {Try{//connect to SQLite's JDBCClass.forName ("Org.sqlite.JDBC");//Create a connection to the database name Zieckey.db if it does not exist in the current directoryConnection Conn =drivermanager.getconnection ("Jdbc:sqlite:zieckey.db"); Statement Stat=conn.createstatement (); Stat.executeupdate ("CREATE table TBL1 (name varchar (), salary int);");//Create a table, two columnsStat.executeupdate ("INSERT INTO tbl1values (' Zhangsan ', 8000);");//Inserting DataStat.executeupdate ("INSERT INTO tbl1values (' LiSi ', 7800);"); Stat.executeupdate ("INSERT into tbl1values (' Wangwu ', 5800);"); Stat.executeupdate ("INSERT into tbl1values (' Zhaoliu ', 9100);"); ResultSet RS= Stat.executequery ("select * from Tbl1;");//Querying Data while(Rs.next ()) {//Print the data you have queriedSystem.out.print ("name =" + rs.getstring ("name") + "");//Column Properties OneSystem.out.println ("salary =" + rs.getstring ("salary"));//Column Properties Two}rs.close (); Conn.close ();//to end a connection to a database}Catch(Exception e) {e.printstacktrace ();}}}
Transferred from: http://free0007.iteye.com/blog/1988151
sqlite-use in Java sqlite-2