上一篇:Java Using SQLite
一、建立 table
表格名稱:CUSTOMER
CREATE TABLE CUSTOMER ( CUS_ID INT PRIMARY KEY NOT NULL, CUS_NAME TEXT NOT NULL, CUS_AGE INT NOT NULL, CUS_ADDRESS CHAR(50), SALARY REAL)
圖1
二、程式
package com.sqlite.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class CreateTableSQLiteJDBC { public static String getTable() { return "CREATE TABLE CUSTOMER " + "(CUS_ID INT PRIMARY KEY NOT NULL," + " CUS_NAME TEXT NOT NULL, " + " CUS_AGE INT NOT NULL, " + " CUS_ADDRESS CHAR(50), " + " SALARY REAL)"; } public static void main(String args[]) { Connection c = null; Statement stmt = null; try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:data/test.db"); stmt = c.createStatement(); stmt.executeUpdate(getTable()); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); }finally{ try { if(null != stmt){ stmt.close(); } } catch (SQLException e) { e.printStackTrace(); } try { if(null != c){ c.close(); } } catch (SQLException e) { e.printStackTrace(); } } System.out.println("Create Table successfully"); System.exit(0); } }
三、建立測試專案
參考:Java Using SQLite
四、執行程式
圖2
下一篇:SQLite Manager 查看 Table
其它文章
沒有留言:
張貼留言