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?

4

1 に答える 1

7

mysqlを使用するタグで述べたので、クエリでIFNULLステートメントを使用して、NULLの代わりにデフォルト値を取得することをお勧めします。

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

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

于 2012-09-11T06:45:48.310 に答える