3

I am using Spring JDBC template for jdbc operations. Since I am using BeanPropertySqlParameterSource, the bean's START_TIME variables is assigned with java.sql.date type. in Oracle db, the column is mentioned as "DATE" type (and don't have TIMESTAMP type, even the db is 10.2 ver)

Now when I set

bean.setStartTime(new Date(System.currentTime()) 

it's storing with date and time stamp as 00:00:00

Please tell me how can i Store the time stamp also.

2 Answers 2

7

You need to use java.sql.Timestamp

 bean.setStartTime(new java.sql.Timestamp(...))

java.sql.Date removes the time part

From the Javadocs:

To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated.

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

Comments

0
java.util.Date today = new java.util.Date();
java.sql.Date d=new java.sql.Date(today.getTime());

1 Comment

Thanks for the answer. However adding some explanation may certainly help the OP.

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.