[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

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.
0
searchsanjaysharma
Asked:
searchsanjaysharma
  • 4
  • 3
  • 3
1 Solution
 
ValeriCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now