second argument. The updateable ResultSet object does not have to be scrollable,
but, when making changes to a ResultSet , we often want to move freely around the
ResultSet rows, so it seems sensible to make the ResultSet scrollable.
Statement statement = connection.createStatement(
As usual, there are three types of change that we can carry out on the data in a
updates (of some/all fi elds of a selected row);
insertions (of new data rows);
deletions (of existing database rows).
We shall take each of these in turn, starting with updates…
At the heart of updating via Java methods, there is a set of updateXXX methods
(analogous to the getXXX methods that we use to retrieve the data from a row
within a ResultSet ), each of these methods corresponding to one of the data types
that may be held in the database. For example, there are methods updateString
and updateInt to update String and int data respectively. Each of these methods
takes two arguments:
a string specifying the name of the fi eld to be updated;
a value of the appropriate type that is to be assigned to the fi eld.
There are three steps involved in the process of updating:
position the ResultSet cursor at the required row;
call the appropriate updateXXX method(s);
call method updateRow .
It is this last method that commits the update(s) to the database and must be
called before moving the cursor off the row (or the updates will be discarded).
results.absolute(2);//Move to row 2 of ResultSet .
(Note here that an 'f' must be appended to the fl oat literal, in order to prevent
the compiler from interpreting the value as a double .)
For an insertion, the new row is initially stored within a special buffer called the
''insertion row' and there are three steps involved in the process:
call method moveToInsertRow ;
call the appropriate updateXXX method for each fi eld in the row;
call method insertRow .