sqlite-use in Java sqlite-2

Source: Internet
Author: User
Tags sqlite

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.