-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Retun of status code on sql calls.
PostPosted: Mon May 10, 2004 9:33 am 
Beginner
Beginner

Joined: Tue Apr 27, 2004 11:16 am
Posts: 23
Hi,

I am executing a stored procedure, other than capturing the resultset, is there a way to capture the returned status code from the sql calls made.

Thanks for the replies.


-Gana.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 12:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
how do you do that in JDBC ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Status code
PostPosted: Mon May 10, 2004 1:56 pm 
Beginner
Beginner

Joined: Tue Apr 27, 2004 11:16 am
Posts: 23
This is how we currently do...

//SPM_SAMPLE is the stored procedure name.
String query = "{ ?=Call SPM_SAMPLE(?) }";

//conn is the Connection object.
CallableStatement stmt = conn.prepareCall(query);

stmt.registerOutParameter(1, java.sql.Types.INTEGER);
stmt.setString(2, sampleInputData);

ResultSet rset = stmt.executeQuery();

int status = rset.getInt(1);

//Is there is any error, status will be set to -1 and status set to 0 when there is no error.


Thanks
Gana.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:17 pm 
Beginner
Beginner

Joined: Tue Apr 27, 2004 11:16 am
Posts: 23
Anybody....does my last note.. get u a clear picture????


-Gana.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:18 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
How is that related to Hibernate?

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:22 pm 
Beginner
Beginner

Joined: Tue Apr 27, 2004 11:16 am
Posts: 23
When Hibernate is supporting stored procedures.. is there a way to capture the return status code from the stored procedure calls.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It doesn't support stored procedures.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:23 pm 
Beginner
Beginner

Joined: Tue Apr 27, 2004 11:16 am
Posts: 23
How about 2.2... ??


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:24 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Not even alpha.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:26 pm 
Beginner
Beginner

Joined: Tue Apr 27, 2004 11:16 am
Posts: 23
http://forum.hibernate.org/viewtopic.php?t=930517

Check Michael's reponse.

-Gana


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
So, checkout v22branch and see for yourself. This is a developer version, you might not be able to use it. We also can't support it on this forum (and I wish my colleagues would stop mentioning it).

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: More on getting the return value from a stored procedure...
PostPosted: Thu Sep 16, 2004 2:40 pm 
Newbie

Joined: Thu Sep 16, 2004 12:44 pm
Posts: 1
Location: Software engineer
The company I work for is considering switching from TopLink to Hibernate. We need to call MS-SQL Server and Oracle 9i stored procedures in our applicaitions and I have the responsibility of figuring out how to work around Hibernate v2.x's lack of explicit stored procedure support.

The information in this forum has been quite helpful in coming up to speed on Hibernate, so I would like to add to the body of knowledge here.

I think that a better answer to Gana's original question would have been that a simple change to his JDBC code would have allowed him to retrieve the return value from the stored procedure.

I believe that all he needed to do was change this statement:

int status = rset.getInt(1);

to

int status = stmt.getInt(1);


Below you'll find a method from a Hibernate test application that calls a very simple stored procedure on a MS-SQL 2000 server. The stored procedure just returns the same value that was passed to it in the input parameter. The test application uses Hibernate 2.1.6 and creates a static SessionFactory when the application starts.

Note that this is demo code; its purpose is to demonstrate how to use a connection object from a Hibernate session to call a stored procedure with JDBC and get the return value. The code isn't meant to demonstrate how to deal with the other real-world issues that arise from using stored procedures in a Hibernate application.

Code:
private Integer callSPWithReturnValue(int inValue) {
int retVal=0;
   try {
      // ReturnValue is the stored procedure name.
      String sqlcall = "{?=Call ReturnValue(?) }";
      Session session = sessionFactory.openSession();
      Connection conn = session.connection();
      CallableStatement cstmt = conn.prepareCall(sqlcall);
      // Initialize the parameter values for the call.
      cstmt.registerOutParameter(1, java.sql.Types.INTEGER);
      cstmt.setInt( 2, inValue);
      Transaction tx = session.beginTransaction();
      // Use the execute() method when the SP does not return a resultset, otherwise use executeQuery.
      cstmt.execute();
      tx.commit();
     
      retVal= cstmt.getInt(1);
   } catch (HibernateException e) {
           e.printStackTrace();
   } catch (SQLException s) {
           s.printStackTrace();
   }
   return new Integer(retVal);
}


I hope this information will be of use to the other stored procedure users out there in the Hibernate user community.

_________________
Al


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.