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
Solved

How to call DB2 procedure using Hibernate

Posted on 2009-06-30
1
1,441 Views
Last Modified: 2013-11-24
Hi
  I am trying to call DB2 procedure from Hibernate.
  I could not get data. The resultset is returned as null.
  Could anyone help.

Thanks

Hibernate Code
===============
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
try {
CallableStatement stmt = session.connection().prepareCall("{? = call SAMPLE.PROCEDURE3()}");
boolean statusFlag = stmt.execute();
tx.commit();
ResultSet rs = stmt.getResultSet();
System.out.println("Test1.main() statusFlag is: "+statusFlag);
}
catch(Exception e)
{
if(tx != null) {
tx.rollback();
}
System.out.println(e.getMessage());
}
finally{
if(session!=null && session.isOpen())
session.close();
}
 
DB2 Procedure
==============
CREATE PROCEDURE SAMPLE.PROCEDURE3 (  )
P1: BEGIN
    DECLARE get_Bank CURSOR WITH RETURN  FOR
    	SELECT ID, BANK_NAME FROM SAMPLE.BANKING;
	OPEN get_Bank;
END P1
 
Data in DB2
=========
ID,BANK_NAME
------------------
1,HDFC
2,CITI
3,AXIS
4,UTO
5,SC
6,SBI
1,HDFC
2,CITI
3,AXIS
4,UTO
5,SC
6,SBI

Open in new window

0
Comment
Question by:ysganta
1 Comment
 

Accepted Solution

by:
ysganta earned 0 total points
ID: 24745158

 Resolved.
 The procedure needs to specify the number of resulsets.

example:
CREATE PROCEDURE SAMPLE.PROCEDURE3 (  )
RESULT SETS 1
P1: BEGIN
DECLARE get_Bank CURSOR WITH RETURN  FOR
SELECT ID, BANK_NAME FROM SAMPLE.BANKING;
OPEN get_Bank;
END P1
 
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 109
Configuration Assistant in DB2 10.1 3 84
session migration servlets 2 42
Unhandled exception type Exception 18 42
November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

792 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