This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parameter index out of bounds:3 is not valid value between 1 and 1

 
cchetan jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi frnds...while using prepared Statement i got a exceptioin "parameter index out of bounds:3 is not valid value between 1 and 1..this comes when i use

"preparedStatement ps;
Connection con;
String sql="insert into table values(?,?,?);
ps=con.preparedStatement(sql);
ps.setInt(1,3);
ps.setInt(2,4);
ps.setString(3,"hi");
ps.execute();
"
please sort out this problem..i need solution urgently.
thanks in advance
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please make sure to post the real code; you haven't specified a table name, so that will probably not execute. It would appear you are trying to insert 3 values into a 1-column table. And there is no such thing as "urgently" on JavaRanch.
 
cchetan jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry boss..i 9 there is no urgent term in javaranch..bt i was fed up by that problem ..but at the last i sorted out that.thanks for concern...
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done sorting it. Please tell us what you did, in case anybody else has the same problem.
 
cchetan jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya sir,..there is a silly mistake by me..i made ps and sql variables as global..so when i use it in a method..it works fine.bt when i called another method in it,then it creates a problem..because in the called method i was using the same ps and sql variables.thats why,the previous ps variable's values is changed..and it was giving that sort type of error..then i sorted out by making a local variable ps in the called method..and as you know,local variable hide the global variable..the previous calling method's ps value did not change..and it worked fine..ok boss:-)
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic