0

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

6
  • what is the type of Hbtimestamp post the code Commented May 14, 2015 at 12:55
  • As well first print the value of rs.getTimestamp("timestamp") before setting it. Commented May 14, 2015 at 12:56
  • The data type is timestamp Commented May 14, 2015 at 13:04
  • This is what i am getting Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp Commented May 14, 2015 at 13:05
  • Go to hibernate configuration file add attribute showsql true. Execute code again and it will print sql equivilaent query in conolse the same query execute in sql prompt and check the result.It looks like your query itself not returning anything. Commented May 14, 2015 at 14:09

1 Answer 1

1

Set in your MySQL

zeroDateTimeBehavior=convertToNull 

Then empty time stamp values will be interpreted as NULLs

Well explained here

Sign up to request clarification or add additional context in comments.

4 Comments

Sorry i did not get ,Can you please help me
I did this one added into URL & it is converted to null
jdbc:mysql://localhost:3306/acc_dev_db?zeroDateTimeBehavior=convertToNull
No i am getting Null value,I want the timestamp in DB

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.