Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

parameter error in preparedstatement

 
Ranch Hand
Posts: 173
2
Netbeans IDE PHP Java
  • 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.
 
Bartender
Posts: 1268
39
IBM DB2 Netbeans IDE Spring Java
  • 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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • 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
 
You firghten me terribly. I would like to go home now. Here, take 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
    Bookmark Topic Watch Topic
  • New Topic