aspose file tools*
The moose likes JDBC 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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
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: 19541
    
  16

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
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: 19541
    
  16

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: 19541
    
  16

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
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

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?
 
Similar Threads
JTable
Persisting one-to-many object using sql-insert
Nested Tag (in Form of Table ) :: not able to submit masterForm
problem with one-to-many child insertion
JTable