Solved

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

Posted on 2013-06-29
10
179 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

932 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now