- 论坛徽章:
- 0
|
Performing Updates
Example聽5.3, 鈥淒eleting Rows in JDBC鈥?/a> illustrates the usage.
Example聽5.3.聽Deleting Rows in JDBC
This example will issue a simple DELETE statement and print out the number of rows deleted.
int foovalue = 500;
PreparedStatement st = conn.prepareStatement("DELETE FROM mytable WHERE columnfoo = ?");
st.setInt(1, foovalue);
int rowsDeleted = st.executeUpdate();
System.out.println(rowsDeleted + " rows deleted");
st.close();
To change data (perform an INSERT, UPDATE, or DELETE) you use the executeUpdate() method. This method is similar to the method executeQuery() used to issue a SELECT statement, but it doesn't return a ResultSet; instead it returns the number of rows affected by the INSERT, UPDATE, or DELETE statement.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4906/showart_18271.html |
|