Solved

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

Posted on 2013-06-29
10
183 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSumClump challenge 9 115
VB Script to add site to Java Exception List 4 77
MySqlDump not dumping triggers 1 31
Java exception bubble up 2 18
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

773 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