This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes How does one insert a column value into an existing record? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "How does one insert a column value into an existing record?" Watch "How does one insert a column value into an existing record?" New topic
Author

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

Steve Howerton
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
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

Joined: Oct 27, 2005
Posts: 20128
    
  30

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Steve Howerton
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
Thanks that was the answer.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20128
    
  30

You're welcome.
Steve Howerton
Ranch Hand

Joined: Oct 18, 2011
Posts: 41
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

Joined: Oct 27, 2005
Posts: 20128
    
  30

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

Joined: Oct 18, 2011
Posts: 41

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

Joined: Oct 14, 2005
Posts: 19739
    
  10

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

Joined: Oct 18, 2011
Posts: 41
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How does one insert a column value into an existing record?
 
It's not a secret anymore!