首页 > 代码库 > sqlite数据库在java中的使用

sqlite数据库在java中的使用

/** *  */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 南阳理工软件学院移动设备应用与开发 * * @date  2014年6月19日 下午9:20:48 */public class SQLiteDemo {        public static void main(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();     }}

 

运行结果:

id=>1,name=>yuchao1id=>2,name=>yuchao2id=>3,name=>yuchao3