Java Connection to SQLite database

Source: Internet
Author: User
Tags sqlite sqlite database

Download the jar package:

Http://www.sqlite.com.cn/Upfiles/source/sqlitejdbc-v033-nested.tgz

 Public classTestsqlite { Public Static voidMain (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 TBL1 values (' Zhangsan ', 8000);");//Inserting DataStat.executeupdate ("INSERT into TBL1 values (' LiSi ', 7800);"); Stat.executeupdate ("INSERT into TBL1 values (' Wangwu ', 5800);"); Stat.executeupdate ("INSERT into TBL1 values (' 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 (); }    }}

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.