Executing an update statement: the UpdateAction( ) method

The updateAction( ) method performs a Transact-SQL update statement. The update action is:

String sql = "update xmp set name = ?, home = ? where id = ?";

It updates the name and home columns for all rows with a given id value.

The update values for the name and home column, and the id value, are specified by parameter markers (?). updateAction( ) supplies values for these parameter markers after preparing the statement, but before executing it. The values are specified by the JDBC setString( ), setObject( ), and setInt( ) methods with these parameters:

For example:

pstmt.setString(1, name);
pstmt.setObject(2, home);
pstmt.setInt(3, id);

After making these substitutions, updateAction( ) executes the update statement.

To simplify updateAction( ), the substituted values in the example are fixed. Normally, applications compute the substituted values or obtain them as parameters.