Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does one insert a column value into an existing record?

 
Steve Howerton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I was trying to insert a value into column of my table for the first time.

There is no exception caught or thrown.
but clearly the rowcount on the update is not a value.
Using Apache derby embedded database.

my DAO () just ignores prepared statement because the syntax must be wrong.

How does one insert a column value into an existing record?

prepared statement in question:




Example of the columns of the table. Please find the book_status as the value I would like to update.


DAO () called:
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out how the UPDATE statement works. You need that one to modify any column of existing records. INSERT is only used to create new records.
 
Steve Howerton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that was the answer.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
Steve Howerton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there way to set a param and a proper sql statement to change the value as shown above if I send in the PK ? I noticed my statement now is changing all the records.
I would like to change only one using the primary key.



I tried to bring in the PK and set it but I have a few bugs to work out before I can confirm it works or not.



Is there some code to confirm that something was updated that can be used here?
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
executeUpdate returns the number of records that were updated (or inserted / deleted with INSERT / DELETE statements). If that's >0 then you have an updated record.
 
Steve Howerton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I was able to update records and change book_status.


Is my code setting the

I do not understand how to set the additional param 'bookNum' .

thanks
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you considered the possibility that setting the second parameter would be very much like setting the first parameter? Which you have code for.
 
Steve Howerton
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was hoping this to be true. I wanted to eliminate this last step as being the error.
I am in the middle of adding functionality and devising a test and on top of that
I have realized a global var problem concerning MVC2 model design. I will
Add this back in and try to finish debugging this mess.
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic