This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes Return Value from Stored Procedure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Return Value from Stored Procedure" Watch "Return Value from Stored Procedure" New topic

Return Value from Stored Procedure

Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
I have a stored procedure with an out parameter so I think it should return a value (correct me if I am wrong). I am calling the stored procedure in my java program.
How do I get the value to my java program. I want to use the returned value in another operation.
Brian Mozhdehi
Ranch Hand

Joined: Aug 17, 2006
Posts: 81
You need to do the following.

Assume stmt is the CallableStatement object that is returned from prepareCall() and all input has been set.

stmt.registerOutParameter(<the position of the output parameter>, java.sql.Types.<whatever type it is>);

Then, after execution:

String value = stmt.getString(<the position of the output parameter>);

or whatever type it is, i.e. stmt.getInt(), etc.

Hope that helps.
Consider Paul's rocket mass heater.
subject: Return Value from Stored Procedure
Similar Threads
After insert statement, how do I get column value populated by DB trigger
How to call stored procedure from Entity Manager if there is out parameter in stored procedure.
How to get a return value from the stored procedure using callable statement
How to store Output variables of a Stored Procedure in java
java stored procedure problems