I have a column in database having datatype DATETIME. I want to set this column value to current date and time using `PreparedStatement. How do I do that?
I have a column in database having datatype DATETIME . I want to set
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
PreparedStatement#setTimestamp()wherein you pass ajava.sql.Timestampwhich is constructed withSystem#currentTimeMillis().Alternativaly, if the DB supports it, you could also call a DB specific function to set it with the current timestamp. For example MySQL supports
now()for this. E.g.Or if the DB supports it, change the field type to one which automatically sets the insert/update timestamp, such as
TIMESTAMPinstead ofDATETIMEin MySQL.