I had this source on my disk. It's a good example. For clarity, I did change the machine, catalog and table name in the source. Hope it helps. It uses the JDBC driver from the JTOpen project.
Notice that with this specific driver you can access the iSeries DB2 database as any other database. Also, the DB2 database on the iSeries is just one of the versions of the IBM Universal Database. However, you can do iSeries specific tricks, even with the JDBC driver. But if you want to stay SQL defaults only, that is fine too.
import java.sql.*;
public class TestSQL {
public static void main(String[] args) {
try {
DriverManager
.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
Connection conn = DriverManager
.getConnection("jdbc:as400://YOURISERIES/YOURLIBRARY");
Statement select = conn.createStatement();
ResultSet rs = select.executeQuery("select * from whatever");
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
for (int x=1; x <= rsmd.getColumnCount(); x++) {
System.out.print(rs.getString(x));
}
System.out.println();
}
} catch (Exception e) {
System.out.println("error: " + e.getMessage());
}
System.exit(0);
}
}