他のバージョンの文書 15 | 14 | 13 | 12 | 11 | 10 | 9.6 | 9.5 | 9.4 | 9.3 | 9.2 | 9.1 | 9.0 | 8.4 | 8.3 | 8.2 | 8.1 | 8.0 | 7.4 | 7.3 | 7.2

8.4. 更新の実行

データを変更(insert、update、delete の実行)するには、 executeUpdate() メソッドを使用します。 executeUpdate() は SELECT を発行する際に使用する executeQuery() と似ていますが、 ResultSet を返すのではなく、挿入、更新、削除文で影響を受けたレコード数を返します。

Example 8-2. 簡単な削除例

以下は、簡単な DELETE を発行し、削除された行数を表示する例です。

int foovalue = 500;
PreparedStatement st = db.prepareStatement("DELETE FROM mytable where columnfoo = ?");
st.setInt(1, foovalue);
int rowsDeleted = st.executeUpdate();
System.out.println(rowsDeleted + " rows deleted");
st.close();