一、建立 DELETE TABLE SQL
public static String getDeleteSql() { return "DELETE from CUSTOMER where CUS_ID=1;"; }
二、程式
package com.sqlite.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; public class DeleteTableSQLiteJDBC { public static String getDeleteSql() { return "DELETE from CUSTOMER where CUS_ID=1;"; } 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"); c.setAutoCommit(false); stmt = c.createStatement(); stmt.executeUpdate(getDeleteSql()); c.commit(); System.out.println("DELETE Table successfully."); } 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.exit(0); } }
三、建立測試專案
參考:Java Using SQLite
四、執行程式
參考:SQLite Manager For Firefox
圖1 修改前
圖2 執行程式
圖3 修改後
五、相關文章
Java Using SQLite
SQLite CREATE TABLE Using Java
SQLite INSERT TABLE Using Java
SQLite SELECT TABLE Using Java
SQLite UPDATE TABLE Using Java
SQLite DELETE TABLE Using Java
其它文章
沒有留言:
張貼留言