• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

java.sql.SQLException: Parameter index out of range (1 > number of parameters, which  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code:
---------------------------------------------------------------
String query="INSERT INTO opr_rt_info VALUES ('"+"?"+"','"+
"?"+"','"+"?"+"','"+"?"+"','"+"?"
+"','"+"?"+"')";
System.out.println(query);
pstmt = conn.prepareStatement(query);
pstmt.setString(1,opr_name1); // Exception is thrown
pstmt.setString(2,opr_mode1);
pstmt.setString(3,rt_name1);
pstmt.setString(4,rt_ch_no1);
pstmt.setString(5,rt_ch_freq1);
pstmt.setString(6,rt_selection_flag1);
int res1=pstmt.executeUpdate(query);
--------------------------------------------------------------------end


java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

Exception is thrown on instruction

pstmt.setString(1,opr_name1);

if anybody has solution then please help me out.
Regards Sachindra
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using a sql string like this:

which will insert six question marks into your table.

If you want to use a PreparedStatement (which is a good thing) get rid of the quotes round the question marks.
[ August 21, 2008: Message edited by: Paul Sturrock ]
 
Sachindra Pratap
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou Paul,
I did same what you suggested ,and it worked.

regards Sachindra
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm facing the same problem.

My java code:



Server log:



mysql table structure:


I'm getting exception at:



I've already registered one user with this. But after that now I'm getting this exception.

Can somebody kindly help?

Thanks
 
imran sujoy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
===SOLVED===

Please forget about it. I found why the error was occurring. I was actually using one single PreparedStatement for two different methods (silly me), and when the flow returned from the called method, it still was the first preparedstatement rather than the new one, hence it couldn't found the parameter in the proper indexed position.

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!