This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JDBC and the fly likes PreparedStatements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "PreparedStatements" Watch "PreparedStatements" New topic
Author

PreparedStatements

Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
I get the following error when I execute my statement:

java.sql.SQLException: Parameter index out of bounds. 8 is not between valid values of 1 and 7

PreparedStatement prepUpdate = bbCon.prepareStatement(updateStmt);
int length = valuesToUpdate.length;

for(int i = 0; i< length;i++){
prepUpdate.setString(i+1, valuesToUpdate[i]);
}

//execute the update Statement
int intUpdate = prepUpdate.executeUpdate();

is there a way I can maybe use the column name instead.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Yes. However you could just fix your programming logic - presubabmy valuesToUpdate is an array longer than 7 values. You need to make sure you have the same number of values to bind to parameters as you have parameters defined in your PreparedStatement.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Patrick Mugabe
Ranch Hand

Joined: Jan 08, 2002
Posts: 132
Thanks but I don't know how I can use the column name instead. I have checked my code fragment and followed it through. valuesToUpdate has 7 values before going into the loop
[ December 05, 2006: Message edited by: Patrick Mugabe ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

D'oh! I am of course wrong. It has to be column index (its only ResultsSets that allow you to access values by field name). Sorry.


I have checked my code fragment and followed it through. valuesToUpdate has 7 values before going into the loop

The exception message suggests otherwise. Are you sure?
 
 
subject: PreparedStatements
 
Similar Threads
String.length() returns strange results
get the length of the string
Getting dimensions of Array[][]
2 dimensional Array!
initialization