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.
You can use an instance of AS400JDBCDataSource or AS400JDBCConnectionPoolDataSource to create the connection to the database that you want to use to access the data for the AS400JDBCRowSet.
The following examples show how you can use the AS400JDBCRowSet class.
Example: Creating, populating, and updating an AS400JDBCRowSet objectDriverManager.registerDriver(new AS400JDBCDriver()); // Establish connection by using a URL. 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(); }Example: Creating and populating an AS400JDBCRowSet object, while getting the data source from JNDI
// 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(); // Establish connection by setting the data source name. 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();