DateTime Java with mysql
Question
I have columns in mysql
id, unique_guid, attribute1, ..., create_time, update_time
for a table.
I want to create a record if it has never been created with create_time, or if it has been created, just replace some/all attributes and update_time. I am using Java, and using mysql connector.
Is there a way I can do this without querying for existence of the record and then updating it, ending up in two queries?
PS: Note that create_time, update_time are not mysql "timestamps", they are "datetime."
Thanks!
Solution
Use ON DUPLICATE KEY UPDATE
: http://dev.mysql.com/doc/refman/5.6/en/insert-on-duplicate.html
It's MySQL specific, but it will do what you are asking.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow