File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Returning value and CallableStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Returning value and CallableStatement" Watch "Returning value and CallableStatement" New topic
Author

Returning value and CallableStatement

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 205

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.
Thanks,
Carey


Sent from my IBM 360 mainframe
Mahesh Bogadi
Greenhorn

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
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

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: http://aspose.com/file-tools
 
subject: Returning value and CallableStatement