This week's giveaway is in the Groovy forum.
We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Insert a timestamp into mysql database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Insert a timestamp into mysql database" Watch "Insert a timestamp into mysql database" New topic
Author

Insert a timestamp into mysql database

Gopu Akraju
Ranch Hand

Joined: Jan 13, 2008
Posts: 242
Hi
I have a column in my mysql database as "submitted" of type "DATETIME" data type.

Basically for every trasaction in a table, I want to add timestamp data in a column "submitted".

How do I do this? Do I have to create through java and try using java bean or is it possible to do directly?
Regards
Gopu
Sid Murrey
Ranch Hand

Joined: Jul 07, 2008
Posts: 58
Maybe java.sql.Timestamp could be helpful?

http://java.sun.com/javase/6/docs/api/java/sql/Timestamp.html
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 42698
    
  32
. . . or a DEFAULT NOW() value in the datetime column.
Sid Murrey
Ranch Hand

Joined: Jul 07, 2008
Posts: 58
Campbell's suggestions sound very very right. Forget the Timestamp class :-)
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

Keep in mind NOW() will use the database time, whereas you may want to use the application server time. For example, if they are out of sync, the database could create records that the application server believes are in the future. In general, its better to have your application server administering time since its making all the decisions.


[OCA 8 Book] [Blog]
 
wood burning stoves
 
subject: Insert a timestamp into mysql database