啥是這個這個SQLite?
是a type of database,不像其他database,SQLite is just a single file在我的電腦
那這個改動有什麼鬼用處呢??
他sort of 讓這個project be from a toy program to a real, database-driven application;
整體的架構會是
/java_project/
├─ Main.java
├─ StudentManager.java
├─ sqlite-jdbc-3.45.2.0.jar
├─ students.db ← SQLite database file在這
然後我載了這個The SQLite JDBC driver (sqlite-jdbc-x.x.x.jar) 他裝滿了用C的SQLite engine 並包裝給java 使用;
整個過程是這樣的:
1.下載 SQLite JDBC 驅動程式:
download 剛剛提到的sqlite-jdbc-3.50.3.0.jar
反正 .jar 是一個 Java 函式庫,讓 Java 能聽懂「SQLite 資料庫」的語言。然後把他放到跟
2.寫程式連線到資料庫
我在 Main.java 裡面寫了這段:
String url = "jdbc:sqlite:students.db";
Connection conn = DriverManager.getConnection(url);
這代表jdbc:sqlite: 告訴 Java「我要連線 SQLite,而students.db 是資料庫檔案名稱
DriverManager.getConnection(url) 則會透過驅動程式建立連線
如果這個檔案不存在,SQLite 會自動建立一個新的 students.db。
這個檔案就是only belong to me 的資料庫(像 Excel 一樣可以存資料表)。
3.最後執行程式就是建成功了
實際操作完並用黃色標示結果: