Java Reference
In-Depth Information
results.updateInt("acctNum", 999999);
results.updateString("surname", "Harrison");
results.updateString("fi rstNames",
"Christine Dawn");
results.updateFloat("balance", 2500f);
However, it is possible that getXXX methods called after insertion will not
retrieve values for newly-inserted rows. If this is the case with a particular database,
then it will be necessary to close the ResultSet and create a new one (using the original
query), in order for the new insertions to be recognised.
To delete a row without using SQL, there are just two steps:
move to the appropriate row;
call method deleteRow .
results.absolute(3); //Move to row 3.
Note that JDBC drivers can handle deletions differently. Some remove the row
completely from the ResultSet , while others use a blank row as a placeholder. With
the latter, the original row numbers are not changed.
Now to bring together all the above 'snippets' of code into one program…
We shall use program JDBCChange from Sect. 7.5 as the starting point for this
example and make the necessary modifi cations to it. The new lines will be shown in
bold below
import java.sql.*;
public class JDBC2Mods
private static Connection connection;
private static Statement statement;
private static ResultSet results;
public static void main(String[] args)
Search WWH ::

Custom Search