ResultSet interfaceYou can use a ResultSet object to access a table of data that was generated by running a query. The table rows are retrieved in sequence. Within a row, column values can be accessed in any order. The data stored in ResultSet is retrieved by using the various get methods, depending on the type of data being retrieved. The next() method is used to move to the next row. The ResultSetMetaData interface determines the types and properties of the columns in a ResultSet. The following example shows how to use the ResultSet interface: |
// Connect to the AS/400. Connection c = DriverManager.getConnection("jdbc:as400://mySystem"); // Create a Statement object. Statement s = c.createStatement(); // Run a query. The result is placed // in a ResultSet object. ResultSet rs = s.executeQuery ("SELECT NAME,ID FROM MYLIBRARY.MYTABLE"); // Iterate through the rows of the ResultSet. while (rs.next ()) { // Get the values from the ResultSet. // The first value is a string, and // the second value is an integer. String name = rs.getString("NAME"); int id = rs.getInt("ID"); System.out.println("Name = " + name); System.out.println("ID = " + id); } // Close the Statement and the // Connection. s.close(); c.close();
[ Legal | AS/400 Glossary ] |