File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Returning value and CallableStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Returning value and CallableStatement" Watch "Returning value and CallableStatement" New topic

Returning value and CallableStatement

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 883

I have a stored procedure that invokes the SQL "return (42)" at the point of completion. (This is Sybase if that makes any difference.) The following is the JDBC I put together to call the stored procedure. The three method calls that use and index work, the three commented out lines that use the column name do not. I have a strong need to be able to use the column name version for flexibility with other stored procedures that have very long parameter lists of which only a subset is needed. If I try to use the index version for argument one, and the named version for the remainder I get a run time error saying that I can't mix them. Actually, the name version runs but it appears that arguments are shifted when they get to the stored procedure. I've tried all sorts of permutations of the registerOutParameter() line, but no luck.

Any insights you could give me would be appreciated.

Understanding the scope of the problem is the first step on the path to true panic
Mahesh Bogadi

Joined: Feb 21, 2013
Posts: 3
I also need the answer to this question.

Can be use a name instead of ? to name the parameter?

e.g. { ret = call ( ?, ?, ? ) };

callablestatement .getString ("ret" )
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3733

As far as I know, pure JDBC doesn't support named parameters. You have to use the question marks for all parameters.

Some JDBC drivers have methods that allow to use named parameters, but this is an extension incompatible with JDBC standard, so it won't work with another JDBC driver.

Edit: the original question concerned passing function/procedure parameters by name. I don't know whether that is supported as part of the JDBC standard, I always pass parameters by position - that always works.
I agree. Here's the link:
subject: Returning value and CallableStatement
jQuery in Action, 3rd edition