The below code examples are from a Genealogy database that I use for examples. The below code is for a MySQL db, the code may need to be modified for a different database.
If you are returning one cursor, then this code should get you started.
Connection conn = null
CallableStatement stproc_stmt = null;
...
//Make connection
...
//Create CallableStatement
stproc_stmt = conn.prepareCall("{call gendata.getMilitary(?)}");
//set all In/Out parameters
stproc_stmt.setString(1, "Y");
//execute
stproc_stmt.execute();
//Get ResultSet
ResultSet rs = stproc_stmt.getResultSet();
while (rs.next()) {
System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3));
} //end while
******************************************************************
If you are returning multiple cursors, then add this code for each additional cursor returned:
******************************************************************
//Get next ResultSet
stproc_stmt.getMoreResults();
rs = stproc_stmt.getResultSet();
while (rs.next()) {
System.out.println(rs.getString("given_name")+" "+rs.getString("last_name")+" "+rs.getInt("birth_year"));
} //end while
Best Regards,
Ricky
CA Application Insight Support