2015-05-14 177 views
0

我有一個Java MVC模型。其中有一個已插入到DB中的DB值的時間戳。我已經在數據庫中聲明瞭數據類型爲時間戳,現在問題是如果我嘗試檢索它顯示空值&不能表示爲java.sql.Timestamp中使用Mysql從數據庫中檢索時間戳數據

聲明:

pstmt = con.prepareStatement("SELECT timestamp, FROM nid where id=?"); 
pstmt.setDouble(1, nidev); 
      rs = pstmt.executeQuery(); 
      if(rs.next()) 
      { 
       timeBean.setHbtimestamp(rs.getTimestamp("timestamp")); 

      } 

Bean類:

private Timestamp hbtimestamp; 

public Timestamp getHbtimestamp() { 
    return hbtimestamp; 
} 
public void setHbtimestamp(Timestamp hbtimestamp) { 
    this.hbtimestamp = hbtimestamp; 
} 

MYDB值被成功插入:2015年5月14日15時45分57秒

輸出:值 '0000-00-00 00:00:00' 不能被表示爲java.sql中。時間戳

+0

「Hbtimestamp」的類型是什麼類型的代碼 –

+0

在設置之前,首先打印'rs.getTimestamp(「timestamp」)'的值。 –

+0

數據類型是時間戳 – Ramesh

回答

1

設置在你的MySQL

zeroDateTimeBehavior=convertToNull 

然後空的時間戳值將被解釋爲空值

很好地解釋here

+0

對不起,我沒有得到,你能幫我嗎 – Ramesh

+0

我做了這一個添加到URL&它被轉換爲空 – Ramesh

+0

jdbc:mysql:// localhost:3306/acc_dev_db?zeroDateTimeBehavior = convertToNull – Ramesh