• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

parameter error in preparedstatement

 
Robert Ingmarsson
Greenhorn
Posts: 27
Java Netbeans IDE PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, world!

I have been struggling with an error i get when i try to update a record using PreparedStatement and its
setString method. I was wondering if anyone could help me out with this one. There must be something i
am missing. I am pretty new to jdbc.

I get the following error message when i try to run the code listed below this theese two lines:

At least one parameter to the current statement is uninitialized

Here is my code



Kind regards,
Robert.
 
Claude Moore
Ranch Hand
Posts: 828
7
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simply, you forgot fourth parameter, corresponding to ACCOUNT parameter in your SQL WHERE clause. For each ? parameter placeholder, you must set a value. Parameter binding is positional, not by name, so if ACCOUNT is present twice in your SQL, you have nevertheless set two parameters for it.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert Ingmarsson wrote:I get the following error message when i try to run the code listed below this theese two lines:

At least one parameter to the current statement is uninitialized

Sometimes an error message can be crystal-clear about what's wrong. And in this case, it definitely is. In your SQL statement I count 4 parameter placeholders (question marks), but I only see 3 statements to set the actual values for these parameters. That's why you get this error when trying to execute this code snippet. You have to set a value for the second occurence of ACCOUNT in your query as well, e.g. adding this statement will solve the issueAnd as you are pretty new to JDBC, it might be useful to have a look at the PreparedStatement section of the JDBC tutorial by Oracle.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic