aspose 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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 170

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
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: 3434
    
  47

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.
 
 
subject: Returning value and CallableStatement
 
Similar Threads
Savepoint in jdbc
Need a disconnected resultset
[B]Problem while calling java stored procedure which connects to db2 [/B]
calling stored procedure
Stored procedure which returns array