In Oracle PL/SQL you can SELECT INTO statement to read exactly one row and assign values of the selected columns to variables. In Java JDBC you have to use the prepared statements:
Oracle:
-- Procedure with SELECT INTO statements CREATE OR REPLACE PROCEDURE sp_processCity(p_name VARCHAR2) AS cnt NUMBER; v_name VARCHAR2(30); v_name_upper VARCHAR2(30); BEGIN SELECT COUNT(*) INTO cnt FROM cities WHERE name = p_name; SELECT name, name_upper INTO v_name, v_name_upper FROM cities WHERE name = p_name; END; /
Java:
public static void sp_processCity(String p_name) { int cnt; String v_name; String v_name_upper; PreparedStatement stmt = conn.prepareStatement("SELECT COUNT(*) FROM cities WHERE name = ?"); stmt.setString(1, p_name); ResultSet rs = stmt.executeQuery(); if (rs.next()) { cnt = rs.getInt(1); } stmt = conn.prepareStatement("SELECT name, name_upper FROM cities WHERE name = ?"); stmt.setString(1, p_name); rs = stmt.executeQuery(); if (rs.next()) { v_name = rs.getString(1); v_name_upper = rs.getString(2); } }
For more information, see Oracle PL/SQL to Java Migration.