close
以下紀錄使用 Java 建立 SQLite 資料庫與建立表格
Step 1:
請先到下列網址抓取 SQLite 與 Java 連線所需要的 JDBC。
https://bitbucket.org/xerial/sqlite-jdbc/downloads/
如下圖,點擊 sqlite-jdbc-3.16.1.jar 下載後 import 到自己的專案中。
Step 2:
連線並且建立資料庫 test.db 與 資料表 testTable 裡面並且包含兩個欄位 name 與 phoneNumber,它們的data type 都是 string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)"); |
文章標籤
全站熱搜