Ramesh
Ramesh

Reputation: 1

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

Upvotes: 0

Views: 148

Answers (1)

StanislavL
StanislavL

Reputation: 57421

Set in your MySQL

zeroDateTimeBehavior=convertToNull 

Then empty time stamp values will be interpreted as NULLs

Well explained here

Upvotes: 1

Related Questions