pro_java thread: Urgent........... Get Result Set from stored Procedure ( multi Rows)
Mohammad Jamous wrote:
>
> I know how to get result set from stored procedure only when the result is
> one row ,
> but I search allot of site about how I can manipulate or get back the multi
> result set from stored procedure.
>
> specially when I want to retrieve like an array of string for example.
>
> Note: what I want is multi result from stored procedure not from
> PreparedStatement.
I'm not exactly sure what you are asking, so there are several possible
answers.
If you want a SINGLE result set which contains more than a single row from the
database, then there should be no difference with what you are currently
doing. It doesn't matter whether a ResultSet has no rows, one row, or many
rows, getting a ResultSet from a stored procedured is the same:
String sql = ...; //sql to call stored procedure
CallableStatement cs = connection.prepareCall(sql);
//set the parameters of the callable statement, then
ResultSet rs = cs.executeQuery();
while (rs.next()) {
//...get column values from result set
}
If you want to know how to get a ResultSet from a stored procedure, then here
are some Oracle examples that may help you:
http://govt.oracle.com/~tkyte/ResultSets/
http://technet.us.oracle.com/tech/java/sqlj_jdbc/htdocs/jdbc_faq.htm#_51_
If you have a procedure that returns more than one ResultSet, then you use
methods of the CallableStatement to retrieve the ResultSets:
boolean result = cs.execute();
while (result) {
rs = cs.getResultSet();
//...get column values
result = cs.getMoreResults();
}
The javadoc for getResultSet() and getMoreResults() is at
http://java.sun.com/products/jdk/1.2/docs/api/java/sql/Statement.html#execute(java.lang.String)