时间:2015-06-25 11:26 来源: 我爱IT技术网 编辑:52微风
说明:
本文改上一篇:SQLite DELETE TABLE Using Java,改为使用PreparedStatement。
一、建立 DELETE TABLE SQL
public static String getUpdateSql() {
return "DELETE from CUSTOMER where CUS_ID=?;";
}二、程序
package com.sqlite.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; public class DeleteTableSQLiteJDBC2 { public static String getUpdateSql() { return "DELETE from CUSTOMER where CUS_ID=?;"; } public static void main(String args[]) { Connection c = null; PreparedStatement ps = null; try { Class.forName("org.sqlite.JDBC"); c = DriverManager.getConnection("jdbc:sqlite:data/test.db"); c.setAutoCommit(false); ps = c.prepareStatement(getUpdateSql()); ps.setInt(1,2); ps.executeUpdate(); c.commit(); System.out.println("DELETE Table successfully."); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } finally { try { if (null != ps) { ps.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 修改后

- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
