简体   繁体   中英

Retrieving Timestamp data from DB using Mysql

I have a Java MVC model.Which has timestamp as one of the DB value which is already inserted into DB.I have declared the data type as Timestamp in DB,Now the problem is If i try to retrieve it is showing null values & can not be represented as java.sql.Timestamp

Statement :

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 Class:

private Timestamp hbtimestamp;

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

MyDB value is successfully inserted :2015-05-14 15:45:57

output: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

Set in your MySQL

zeroDateTimeBehavior=convertToNull 

Then empty time stamp values will be interpreted as NULLs

Well explained here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM