• 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

Number of parameters in CallableStatement is less than the number of arguments in SP

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Database: MS SQL Server
Java: 1.6

The stored proc which my frontend would use has 3 input parameters with default values (NULL) for all 3 parameters.



But my frontend would use just only 1 parameter out of 3. For this I have my JDBC code like this using the named parameter feature.



I get an error "The index 3 is out of range."

This JDBC code works fine if I pass all 3 parameters (or) if I pass only the first parameter login_id. I don�t think the JDBC CallableStatement requires same number of parameters as the backend strored proc.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It might work if you set the unused parameters to SQL NULL.

 
Vijay Rajaram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, that would work but that is not what I want to do. Reason: What if someone adds a new argument in the stored proc? The stored procs are usually used by many people in real time. And for some requirement they would need a new argument (of course with default value) added to the proc.
 
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vijay Rajaram:
yes, that would work but that is not what I want to do. Reason: What if someone adds a new argument in the stored proc? The stored procs are usually used by many people in real time. And for some requirement they would need a new argument (of course with default value) added to the proc.



if your intention is for your default value to be null... your procedure will never return a value unless all arguments are supplied... in SQL null can never be compared to anything.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


They shouldn't change this stored procedure, they should create a new one that matches their requirement.

What if someone deletes the stored procedure?

What if someone changes the name of the stored procedure?

What if someone changes the SQL statement in the stored procedure?

I'm sure there are a few more "what ifs" that may apply. What you have to decide is how many "what ifs" will you attempt to handle with the Java code?
[ December 23, 2008: Message edited by: James Clark ]
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vijay Rajaram:
yes, that would work but that is not what I want to do. Reason: What if someone adds a new argument in the stored proc? The stored procs are usually used by many people in real time. And for some requirement they would need a new argument (of course with default value) added to the proc.




SQL procedures support overloading.
[ December 24, 2008: Message edited by: Paul Campbell ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic