• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

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

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic