• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CallableStatement and parameterName

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!!
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moody,
There is a good article on this. Basically the names of the parameters need to match the names declared in your stored procedure.
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it possible to define named parameters with named PL/SQL notation, like this

and later set values with methods like this
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Guram!

Which database are you using? I think that not all databases support using named parameters, and some provide database-specific extensions for this functionality.
 
Guram Savinov
Greenhorn
Posts: 24
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm interested in Oracle database.
As far as I know it's possible to define PL/SQL parameters (names with '=>' symbols after it) and use JDBC parameters (names with doublequotes prefix).
Look for example in my previous post.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic