The use of SQLite database in Java

Source: Internet
Author: User
Tags sqlite sqlite database

/** *  */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

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.