SQLite JDBC

SQLite JDBC

http://www.zentus.com/sqlitejdbc/

사용법

 1 import java.sql.*;
 2 
 3 public class Test {
 4   public static void main(String[] args) throws Exception {
 5     Class.forName("org.sqlite.JDBC");
 6     Connection conn =
 7       DriverManager.getConnection("jdbc:sqlite:test.db");
 8     Statement stat = conn.createStatement();
 9     stat.executeUpdate("drop table if exists people;");
10     stat.executeUpdate("create table people (name, occupation);");
11     PreparedStatement prep = conn.prepareStatement(
12       "insert into people values (?, ?);");
13 
14     prep.setString(1, "Gandhi");
15     prep.setString(2, "politics");
16     prep.addBatch();
17     prep.setString(1, "Turing");
18     prep.setString(2, "computers");
19     prep.addBatch();
20     prep.setString(1, "Wittgenstein");
21     prep.setString(2, "smartypants");
22     prep.addBatch();
23 
24     conn.setAutoCommit(false);
25     prep.executeBatch();
26     conn.setAutoCommit(true);
27 
28     ResultSet rs = stat.executeQuery("select * from people;");
29     while (rs.next()) {
30       System.out.println("name = " + rs.getString("name"));
31       System.out.println("job = " + rs.getString("occupation"));
32     }
33     rs.close();
34     conn.close();
35   }
36 }

댓글

이 블로그의 인기 게시물

자바 암호화 확장 (JCE) 관련 자바 1.8.0_151 이후 변경 사항

좌표 변환: 회전 이동

HTTP POST