File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PreparedStatements

 
Patrick Mugabe
Ranch Hand
Posts: 132
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Patrick Mugabe
Ranch Hand
Posts: 132
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic