I\'m using a Java method to convert the date into suitable format:
private Timestamp toTimeStamp(String s) throws java.text.ParseException
{
Timestam
There are 2 problems:
yyyy-MM-dd hh:mm:ss.S
can never match 30-Jun-12
. You need dd-MMM-yy
. See also SimpleDateFormat javadoc.So this should do:
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy", Locale.ENGLISH);
Date date = sdf.parse("30-Jun-12");
A third problem, which is actually more a design matter, you should not be using java.sql.Timestamp
(and other SQL specific date types) anywhere in your model/business layer (you originally tagged the question JSF). You should only use it in your data layer. Use java.util.Date
instead and convert only at exactly the moment you need to persist it in the DB like so
preparedStatement.setTimestamp(1, new Timestamp(date.getTime()));