5

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?

AlwaysALearner
  • 6,320
  • 15
  • 44
  • 59
  • if possibly you wanted to change datetime to timestamp, there is a simple (and robust) solution is to `val_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP`. The other option is to use trigger to insert default values as `NOW()` – Nishant Sep 11 '12 at 06:48

1 Answers1

7

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

Najzero
  • 3,164
  • 18
  • 18