日期:2014-05-16 浏览次数:20607 次
package com.esri; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class TestSqlite { /** * @param args */ public static void main(String[] args) { // System.setProperty("java.library.path", "."); try { Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager .getConnection("jdbc:sqlite:c:/test3.db"); // 建立事务机制,禁止自动提交,设置回滚点 conn.setAutoCommit(false); Statement stat = conn.createStatement(); stat.executeUpdate("create table people (name, occupation);"); stat.executeUpdate("insert into people values ('Gandhi', 'politics');"); stat.executeUpdate("insert into people values ('Turing', 'computers');"); stat.executeUpdate("insert into people values ('Wittgenstein', 'smartypants');"); conn.commit(); ResultSet rs = stat.executeQuery("select * from people;"); while (rs.next()) { System.out.println("name = " + rs.getString("name")); System.out .println("occupation = " + rs.getString("occupation")); } rs.close(); conn.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;