If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to return a cursor in DB2 stored procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-17-07, 23:30
av_domain av_domain is offline
Registered User
 
Join Date: Dec 2007
Posts: 6
How to return a cursor in DB2 stored procedure

Hi all ,

I want to return the cursor in db2 to retrieve the resultset from
my java application .Keeping the cursor open dosen't help and the resultset always returns a null though the procedure runs fine from the command line. Any ideas .

Regards,
Av~

CallableStatement stmt3 = HibernateApp.getHibernateSession().connection().pr epareCall("{call answers_select_id( ? )}");
stmt3.setString(1,20);
stmt3.execute();
ResultSet rs1 = stmt3.getResultSet();
System.out.println("rs1 " + rs1); --> returns null
Reply With Quote
  #2 (permalink)  
Old 12-18-07, 00:18
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
I am not a Java programmer, but I would check out this manual and see if it helps You:
ftp://ftp.software.ibm.com/ps/produc...S/db2a1e81.pdf
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 12-18-07, 01:44
av_domain av_domain is offline
Registered User
 
Join Date: Dec 2007
Posts: 6
Thanks for that quick reply Marcus . I'll chk tht out
Reply With Quote
  #4 (permalink)  
Old 12-18-07, 08:04
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Make sure there is no automatic commit during the execute() call; it would close the cursor.
Reply With Quote
  #5 (permalink)  
Old 12-18-07, 09:26
av_domain av_domain is offline
Registered User
 
Join Date: Dec 2007
Posts: 6
can u please tell me how do I do that ? I am new to db2 . I tried Connection.setAutoCommit(false) - there was no use

The procedure is given below .

CREATE PROCEDURE answers_select_id (IN question_id bigint )
P1:BEGIN
DECLARE cursor1 CURSOR WITH RETURN TO CLIENT FOR
SELECT a.answer_id from answers as a where a.question_id = question_id;
open cursor1;
END P1;

Everything works so smooth in mysql but DB2 returns a null resultset always

Last edited by av_domain; 12-18-07 at 09:37.
Reply With Quote
  #6 (permalink)  
Old 12-18-07, 09:53
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Add the WITH HOLD clause to the cursor declaration inside the procedure or set the auto-commit property for your Java connection object to off.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #7 (permalink)  
Old 12-19-07, 00:12
av_domain av_domain is offline
Registered User
 
Join Date: Dec 2007
Posts: 6
I tried

CREATE PROCEDURE answers_select_id (IN question_id bigint )
P1:BEGIN
DECLARE cursor1 CURSOR WITH HOLD WITH RETURN TO CLIENT FOR
SELECT a.answer,a.answer_id from answers as a where a.question_id = question_id;
open cursor1;
END P1;

I tried that but sill a null resultset ... Everything is fine from the command line
Reply With Quote
  #8 (permalink)  
Old 12-19-07, 01:12
av_domain av_domain is offline
Registered User
 
Join Date: Dec 2007
Posts: 6
Tnx Guys adding DYNAMIC RESULT SETS 1 solved the problem . Thanks again for all your replies
Reply With Quote
  #9 (permalink)  
Old 01-14-10, 05:06
imamulu_tunduru imamulu_tunduru is offline
Registered User
 
Join Date: Jan 2010
Posts: 3
Smile Thanks,

asasasasasa

Last edited by imamulu_tunduru; 01-14-10 at 23:13.
Reply With Quote
  #10 (permalink)  
Old 01-14-10, 11:43
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Oh, two and a half year is enough to understand HOW !

Good job !
Reply With Quote
  #11 (permalink)  
Old 01-14-10, 23:09
imamulu_tunduru imamulu_tunduru is offline
Registered User
 
Join Date: Jan 2010
Posts: 3
sdasasasasasa
Reply With Quote
  #12 (permalink)  
Old 01-14-10, 23:14
imamulu_tunduru imamulu_tunduru is offline
Registered User
 
Join Date: Jan 2010
Posts: 3
Quote:
Originally Posted by Lenny77 View Post
Oh, two and a half year is enough to understand HOW !

Good job !
''I'm Very new to DB2.. You..."
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On