Solved

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

Posted on 2013-06-29
10
192 Views
Last Modified: 2013-07-15
I have a n s ql procedure which is rerturning 2 result sets. How to assign it to resultset.
0
Comment
Question by:searchsanjaysharma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 16

Accepted Solution

by:
Valeri earned 500 total points
ID: 39286577
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 39286578
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
 

Author Comment

by:searchsanjaysharma
ID: 39286583
I am using Sql server. It is giving Incompatible type when i declare array of resultset
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Valeri
ID: 39286596
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
 

Author Comment

by:searchsanjaysharma
ID: 39286601
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 39286622
Those are two independent statements and are not returned by the procedure, just used in it.
0
 
LVL 16

Expert Comment

by:Valeri
ID: 39286629
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 39286644
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
 

Author Closing Comment

by:searchsanjaysharma
ID: 39326066
tx
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39326088
Your SP is most likely wrong
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Suggested Courses

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question