Meaningless Drivel is fun!*
The moose likes JDBC and the fly likes Timestamp not updating in mysql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Timestamp not updating in mysql" Watch "Timestamp not updating in mysql" New topic
Author

Timestamp not updating in mysql

Jean Bodemer
Greenhorn

Joined: Apr 20, 2004
Posts: 3
Hi,

I'm doing updates to records thru Java and JDBC but the timestamp field doesn't update.

An example:
Address has only two fields
Line1 - varchar(40)
UpdateTime - timestamp

ResultSet rs = this.doQuery("SELECT * FROM address WHERE address.key = 1", true);
rs.updateString("Line1", "street addr");
rs.updateRow();
The above does not update the UpdateTime timestamp.

If however I do a query
"Update address set line1 = 'street addr' where address.key = 1"
Then the timestamp is updated.

Any idea how I can get past this problem?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
may be this mySQL driver problem. refer this
Jean Bodemer
Greenhorn

Joined: Apr 20, 2004
Posts: 3
Originally posted by adeel ansari:
may be this mySQL driver problem. refer this


Hi adeel,

The problem you refer to is not really a problem but due to the type of table selected which does not have transaction support.

It would appear as if the ResultSet object is just a staging area that keeps tabs on all the objects retrieved and re-writes them when updating. So if I don't update timestamp it just re-writes the old value.

I don't want this to happen and I don't want to update the timestamp on the client as the time may not be the same as the server. Is there a way to force the timestamp field to be updated or a way to remove it from the rowset?

Jean
Jean Bodemer
Greenhorn

Joined: Apr 20, 2004
Posts: 3
I managed to get past this issue by setting the timestamp = null before the updateRow() statement

rs.updateTimeStamp("updaterow", null);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Timestamp not updating in mysql
 
Similar Threads
Help with line feed line break characters
Storing and Retriving Images from DB(Oracle) using JSP/Servlets
problem in displaying form elements based on no. of addresses
namespace doubt
CMR Relations one-to-many