Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return a default timestamp object instead of null

I have a Timestamp object-

java.sql.Timestamp time = null;

and I have a datetime value val_time in a DB table.

val_time datetime

The situation is, while performaing an operation, this val_time is not getting updated (which is pretty normal in my case). While reading from DB, naturally the datetime value will be null. So the timestamp object will also be null. My question is - can we get some default value other than null?

like image 934
AlwaysALearner Avatar asked Sep 11 '12 06:09

AlwaysALearner


1 Answers

since you stated in the tags you use mysql, I would recommend you using IFNULL statement in your query to get a default value instead of NULL then.

SELECT IFNULL(colname, your-default-value) FROM xyz;

http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_ifnull

like image 124
Najzero Avatar answered Oct 13 '22 08:10

Najzero