1 package com.hedalixin; 2 import java.sql.Connection; 3 import java.sql.DriverManager; 4 import java.sql.ResultSet; 5 import java.sql.Statement; 6 7 /** 8 * @author Chrome 9 * 10 */ 11 public class JavaSqlite { 12 13 /** 14 * @param args 15 */ 16 public static void main(String[] args) { 17 // TODO Auto-generated method stub 18 try { 19 // 连接SQLite的JDBC 20 21 Class.forName("org.sqlite.JDBC"); 22 23 // 建立一个数据库名zieckey.db的连接,如果不存在就在当前目录下创建之 24 25 Connection conn = DriverManager 26 .getConnection("jdbc:sqlite:database.db"); 27 Statement stat = conn.createStatement(); 28 stat.executeUpdate("create table tbl1(name varchar(20), salary int);");// 创建一个表,两列 29 stat.executeUpdate("insert into tbl1 values(‘ZhangSan‘,8000);"); // 插入数据 30 stat.executeUpdate("insert into tbl1 values(‘LiSi‘,7800);"); 31 stat.executeUpdate("insert into tbl1 values(‘WangWu‘,5800);"); 32 stat.executeUpdate("insert into tbl1 values(‘ZhaoLiu‘,9100);"); 33 ResultSet rs = stat.executeQuery("select * from tbl1;"); // 查询数据 34 while (rs.next()) { // 将查询到的数据打印出来 35 System.out.print("name = " + rs.getString("name") + " "); // 列属性一 36 System.out.println("salary = " + rs.getString("salary")); // 列属性二 37 } 38 rs.close(); 39 conn.close(); // 结束数据库的连接 40 41 } catch (Exception e) { 42 e.printStackTrace(); 43 } 44 45 } 46 47 }
转来自用!
转载自:http://blog.csdn.net/salc3k/article/details/6823299