• 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

SQL update JDBC GUI app - Update not working!

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello! I'm having an issue with UPDATE in my program. It is java and I'm using SQLite. Basically just trying to update a table's information VIA the GUI JTextField's.

This is the relevant code:


This is in a separate class:



It is giving me a "Values not bound to statement" error within eclipse. I have tried so many variations of the UPDATE statement here, even different configurations of "PreparedStatement"

Without the where statement it kind of works, but it just replaces every value with the values in the txtfieldboxes. So What where statement could I use? I think that may be part of the problem.

The only other thing I can come up with right now is that I have book_id, book_name, book_author and quantity fields and I am not using the book_id field, which should be the first field. So maybe it's expecting it in that order and it's not getting the right column/row.

Thanks for any help!
 
Rancher
Posts: 3163
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see 4 parameters in the PreparedStatement, but you only set values for 3 of them.
 
Adam Grey
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry. Are you referring to this: ?
 
Marshal
Posts: 25483
67
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Adam Grey wrote:It is giving me a "Values not bound to statement" error within eclipse. I have tried so many variations of the UPDATE statement here, even different configurations of "PreparedStatement"

Without the where statement it kind of works, but it just replaces every value with the values in the txtfieldboxes. So What where statement could I use? I think that may be part of the problem.



Yes, like Rob said there are four parameters in that PreparedStatement but you've only bound three of them to actual values. The fourth one is still unbound.

But you're getting things all mixed up in your mind, I think. First step: design an SQL statement which updates one row of your table. The one you have there looks reasonably good but typically your Books table should have a primary key, and I don't think that book_name should be that key. Don't you have an ID number or something?

Then once you have that SQL, put in the question marks where your code is going to fill in values at run time. Just like you did there, really. And don't forget to assign values to all of them before executing the SQL.
 
Adam Grey
Ranch Hand
Posts: 35
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help! For some reason it did not register that I had to get the value of the WHERE clause. Yes I have a book_id primary key that I was able to use. It works now.

Also, thanks for being nice!
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic