The AS400JDBCRowSet class represents a connected rowset that encapsulates a JDBC result set. The methods on AS400JDBCRowSet are very similar to those of the AS400JDBCResultSet.
The database connection is maintained while in use. Set either the URL property or the dataSourceName property to specify how to establish the database connection. Set the command property to specify how to create a PreparedStatement.
You can connect AS400JDBCRowSets to an AS400JDBCDataSource object and read data from the data source object.
Also, you can register AS400JDBCRowSet objects by using a Java Naming and Directory Interface (JNDI) service provider. For more information on JNDI service providers, see AS/400 Toolbox for Java reference links.
The following examples show how you can use the AS400JDBCRowSet class.
DriverManager.registerDriver(new AS400JDBCDriver()); AS400JDBCRowSet rowset = new AS400JDBCRowSet("jdbc:as400://mySystem","myUser", "myPassword"); // Set the command used to populate the list. rowset.setCommand("SELECT * FROM MYLIB.DATABASE"); // Populate the rowset. rowset.execute(); // Update the customer balances. while (rowset.next()) { double newBalance = rowset.getDouble("BALANCE") + july_statements.getPurchases(rowset.getString("CUSTNUM")); rowset.updateDouble("BALANCE", newBalance); rowset.updateRow(); }
// Get the data source that is registered in JNDI (assumes JNDI environment is set). Context context = new InitialContext(); AS400JDBCDataSource dataSource = (AS400JDBCDataSource) context.lookup("jdbc/customer"); AS400JDBCRowSet rowset = new AS400JDBCRowSet(); rowset.setDataSourceName("jdbc/customer"); rowset.setUsername("myuser"); rowset.setPassword("myPasswd"); // Set the prepared statement and initialize the parameters. rowset.setCommand("SELECT * FROM MYLIBRARY.MYTABLE WHERE STATE = ? AND BALANCE > ?"); rowset.setString(1, "MINNESOTA"); rowset.setDouble(2, MAXIMUM_LIMIT); // Populate the rowset. rowset.execute();