Java Reference
In-Depth Information
both forwards and backwards through the rows. The difference between these two
is that TYPE_SCROLL_SENSITIVE causes any changes made to the data rows to be
refl ected dynamically in the ResultSet object, whilst TYPE_SCROLL_INSENSITIVE
does not. [More about this in the next section.]
There are two possible values that the second argument to createStatement
can take. These are identifi ed by the following static constants in interface
ResultSet :
￿ CONCUR_READ_ONLY
￿ CONCUR_UPDATABLE
As is probably obvious from their names, the first means that we cannot
make changes to the ResultSet rows, whilst the second will allow changes to be
made (and to be refl ected in the database, as will be seen shortly!).
Example
For this fi rst example involving a scrollable ResultSet , we shall simply modify the
code for the earlier program JDBCSelect by inserting lines that will iterate through
the ResultSet rows starting from the last row, displaying the contents of each row
(immediately after traversing the ResultSet in the forward direction and displaying
the contents, as in the original program). For ease of comparison with the original
program, the new and changed lines relating to the introduction of a scrollable
ResultSet will be shown in bold.
In order to avoid code duplication, the lines that display the contents of an
individual row from the ResultSet have been place inside a method called showRow
that is called from two places in the code, but these changes do not directly involve
the scrollable ResultSet and have not been shown in bold.
import java.sql.*;
public class JDBCScrollableSelect
{
private static Connection connection;
private static Statement statement;
private static ResultSet results;
public static void main(String[] args)
{
try
{
connection = DriverManager.getConnection(
"jdbc:odbc:Finances","","");
}
Search WWH ::




Custom Search