-->
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.  [ 2 posts ] 
Author Message
 Post subject: Trouble calling stored function/procedure with return/output
PostPosted: Tue Sep 28, 2010 5:11 am 
Beginner
Beginner

Joined: Thu Oct 16, 2008 11:19 am
Posts: 23
Location: Norway
I seem to be stuck. Basically what I want to do is call a stored function or procedure that has one input variable and one output/return variable. The latter is a string which basically gives a status of the task performed. The function/procedure can look like this:

FUNCTION DO_STUFF ( IN_NUMBER IN NUMBER ) RETURN VARCHAR2 IS

PROCEDURE DO_STUFF ( IN_NUMBER IN NUMBER, OUT_STRING OUT VARCHAR2 ) IS

I have one "method" which I have tried calling as both a function and a procedure, but I struggle getting the return string. I have looked at the namedQuery-mapping way of doing it, but it only seems to allow return values that are either a mapped class or columns. Mine is just a string I make up as I go.

Any advice on how to achieve this?


Top
 Profile  
 
 Post subject: Re: Trouble calling stored function/procedure with return/output
PostPosted: Mon Oct 11, 2010 7:22 am 
Beginner
Beginner

Joined: Thu Oct 16, 2008 11:19 am
Posts: 23
Location: Norway
I found out how to do this, by the way, but the connection() method is deprecated, so it is not the ideal solution. Here it is with the procedure version of the method:

Code:
try
{
    Session session = getSession();
    String sql = "{CALL PACKAGE.PROCEDURE(?, ?)}";
    CallableStatement statement = session.connection().prepareCall( sql );

    statement.setLong(1, longParameter);
    statement.registerOutParameter(2, Types.VARCHAR);

    statement.execute();
    return statement.getString(2);
}
catch ( SQLException ex )
{
    // Whatever you want to do
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.