aspose file tools*
The moose likes JDBC and the fly likes parameter  index out of bounds:3 is not valid value between 1 and 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "parameter  index out of bounds:3 is not valid value between 1 and 1" Watch "parameter  index out of bounds:3 is not valid value between 1 and 1" New topic
Author

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

cchetan jain
Ranch Hand

Joined: Jul 05, 2009
Posts: 30
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
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

Joined: Jul 05, 2009
Posts: 30
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
Well done sorting it. Please tell us what you did, in case anybody else has the same problem.
cchetan jain
Ranch Hand

Joined: Jul 05, 2009
Posts: 30
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

Joined: Oct 13, 2005
Posts: 40052
    
  28
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: parameter index out of bounds:3 is not valid value between 1 and 1