In Oracle PL/SQL you can use the FOR loop statement to open a cursor and fetch rows. In Java JDBC you can open ResultSet and use while() statement to iterate rows.
Oracle:
-- Procedure that fetches rows from a cursor CREATE OR REPLACE PROCEDURE sp_printCities AS CURSOR c1 IS SELECT name FROM cities; BEGIN FOR rec IN c1 LOOP DBMS_OUTPUT.PUT_LINE('City: ' || rec.name); END LOOP; END; /
Java:
public static void spPrintCities() { String c1 = "SELECT name FROM cities"; PreparedStatement stmt = conn.prepareStatement(c1); ResultSet rs = stmt.executeQuery(); while(rs.next()) { System.out.println("City: " + rs.getString("name")); } }
For more information, see Oracle PL/SQL to Java Migration.