close

undefined

以下紀錄使用 Java 建立 SQLite 資料庫與建立表格

Step 1:

請先到下列網址抓取 SQLite 與 Java 連線所需要的 JDBC。

https://bitbucket.org/xerial/sqlite-jdbc/downloads/

如下圖,點擊 sqlite-jdbc-3.16.1.jar 下載後 import 到自己的專案中。

1.JPG

 

Step 2:

連線並且建立資料庫 test.db 與 資料表 testTable 裡面並且包含兩個欄位 name 與 phoneNumber,它們的data type 都是 string

Class.forName("org.sqlite.JDBC");
// create a database connection
connection = DriverManager.getConnection("jdbc:sqlite:test.db");
Statement statement = connection.createStatement();
// check whether it exists the table "testTable"
statement.executeUpdate("drop table if exists testTable");
// create db named testTable and it has two columns name and phoneNumber
statement.executeUpdate("create table testTable (name string, phoneNumber string)");
view raw gistfile1.txt hosted with ❤ by GitHub

 

arrow
arrow
    創作者介紹
    創作者 葛瑞斯肯 的頭像
    葛瑞斯肯

    葛瑞斯肯樂活筆記

    葛瑞斯肯 發表在 痞客邦 留言(0) 人氣()