How to return 2 recordsets in java and how to refer them

I have a n s ql procedure which is rerturning 2 result sets. How to assign it to resultset.
searchsanjaysharmaAsked:
Who is Participating?
 
ValeriConnect With a Mentor Commented:
You just have to register two different out parameters in this way

callableStatement = dbConnection.prepareCall("{call getTWOCursor(?,?)}");

callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
callableStatement.registerOutParameter(2, OracleTypes.CURSOR);

// execute getTWOCursor store procedure
callableStatement.executeUpdate();

then read both Recordsets in this way:

rs1 = (ResultSet) callableStatement.getObject(1);
rs2 = (ResultSet) callableStatement.getObject(2);
0
 
CEHJCommented:
Why have you got two ResultSet and how are they related? If there's a good reason to return two (which frankly i doubt) then you can return ResultSet[]
0
 
searchsanjaysharmaAuthor Commented:
I am using Sql server. It is giving Incompatible type when i declare array of resultset
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ValeriCommented:
I've never heard about returning of  ResultSet[] ?! But I'm agree that if there is a need of returning of  ResultSet[], then there is something wrong in the design of the application.
0
 
searchsanjaysharmaAuthor Commented:
I mean to say what if the procedure has the following set of statements.

create procedure sp_get
as
begin
select uname,password where dept='cse'
select count(*) from dept
end
0
 
CEHJCommented:
Those are two independent statements and are not returned by the procedure, just used in it.
0
 
ValeriCommented:
It's OK. If he return them as out parameters then there is no problem to read them as I showed in my first comment. I think that it's normal and right.
Ignoring that the second parameter is not cursor, it is "Int".
I mean in the example "sp_get" that the author posted.
0
 
CEHJCommented:
It's OK. If he return them as out parameters then there is no problem to read them as I showed in my first comment. I think that it's normal and right.

Yes, 'if'. In the example posted nothing is returned.

I think that it's normal and right
There, i have to disagree. If you can show me several examples of where more than one cursor is returned from a procedure or function, then i would reassess it.

The question asked is "How to return 2 recordsets IN JAVA" (my emphasis). The answer to that is to use ResultSet[], IF it seems legitimate
0
 
searchsanjaysharmaAuthor Commented:
tx
0
 
CEHJCommented:
Your SP is most likely wrong
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.