I have a String as "2015-12-07"
and I want to convert it to java.util.Date
. Is it possible? If yes, please tell how. I am using this date to insert into MySQL column of DATETIME
type using Hibernate.
How property for it in entity class is:
MyEntity.java
@Column(name="xyz")
@Temporal(TemporalType.TIMESTAMP)
private java.util.Date date;
//setter and getter for date
In main I am doing like this:
class Test{
public static void main(String[] args) throws ParseException{
String str="2015-12-07";
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date date=sdf.parse(str);
MyEntity me=new MyEntity();
me.setDate(date);
//persisting into db
}
}
what happens is code runs fine but nothing is being inserted into column