aspose file tools*
The moose likes JDBC and the fly likes CallableStatement and parameterName 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 "CallableStatement and parameterName" Watch "CallableStatement and parameterName" New topic
Author

CallableStatement and parameterName

Moody Hopkins
Greenhorn

Joined: Nov 24, 2003
Posts: 10
How do you use the CallableStatement and parameterNames?
I do not want to use the indexes (indi?) and wildcards if possible.
I know how to use the ? type statements.
I would like to use these type of "setX" methods:
setString(String parameterName, String x)
instead of the :
setString(int parameterIndex, String x)
type methods.
Is this possible? If so, how do I create the statement?
Thanks!!!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Moody,
There is a good article on this. Basically the names of the parameters need to match the names declared in your stored procedure.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Loren Rosen
Ranch Hand

Joined: Feb 12, 2003
Posts: 156
Oracle supports precisely what you want, if you use OracleCallableStatement. That, of course, is specific to Oracle, but I think the technique described in the article Jeanne mentions is also Oracle-specific.
Moody Hopkins
Greenhorn

Joined: Nov 24, 2003
Posts: 10
Thank you very much for the link! However, after reading the article, it seems that it still uses the positional notation. The only difference is the parameters are named in the stored procedure. The java code still has to know the order of the parameters. This is what I would like to avoid.
Perhaps this is not possible? But it must be, why else do we have the functions overidden with named parameters?
What I would like to do is avoid the ? thing altogether.
Thanks!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Moody,
In this code from the article, it shows how you are defining the order in your java code. While you still set the parameters using indexes, these numbers are based on the order set in the java code. So if you wanted p_status to be #1, you would put it first.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: CallableStatement and parameterName
 
Similar Threads
Jrun, jsp:setProperty, null string array elements
CallableStatement throwing data conversion error (Oracle)
Problem using Callable Statement
Allowing unchanged values in mySQL update PreparedStatement
Java assert vs dedicated Assert