SQLITE是一个轻型的数据库,广泛应用与嵌入式系统当中,支持多种开发语言,C,PHP,Perl,Java,C#,Python。它有体积小,效率高,可移植性好的优点 SQLite及sqlite-jdbc下载地址:见附件 JAVA-DEMO
Java代码



- public class Test {
- public static void main(String[] args) throws Exception {
- Class.forName("org.sqlite.JDBC");
- Connection conn =
- DriverManager.getConnection("jdbc:sqlite:demo.db");
- Statement stat = conn.createStatement();
- stat.executeUpdate("drop table if exists people;");
- stat.executeUpdate("create table people (name,occupation);");
- PreparedStatement prep = conn.prepareStatement(
- "insert into people values (?,?);");
- prep.setString(1,"Gandhi");
- prep.setString(2,"politics");
- prep.addBatch();
- prep.setString(1,"Turing");
- prep.setString(2,"computers");
- prep.addBatch();
- prep.setString(1,"Wittgenstein");
- prep.setString(2,"smartypants");
- prep.addBatch();
- conn.setAutoCommit(false);
- prep.executeBatch();
- conn.setAutoCommit(true);
- ResultSet rs = stat.executeQuery("select * from people;");
- while (rs.next()) {
- System.out.println("name = " + rs.getString("name"));
- System.out.println("job = " + rs.getString("occupation"));
- }
- rs.close();
- conn.close();
- }
- }
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|