Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vijay Rajaram
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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.
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paul Campbell
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • 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.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic