It seems there is an issue with java.sql.TimeStamp class, valueOf() method.
When we execute: Timestamp.valueOf("2008-1-26 12:12:12")
Sample code:
public class TimestampTest {
public static void main(String[] args) {
Timestamp t = Timestamp.valueOf("2005-1-01 10:20:50.00");
}
}
Following exception is received:
Exception in thread "main" java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
at java.sql.Timestamp.valueOf(Timestamp.java:194)
The Java version I am using is: jdk1.6.0_10.
The above line of code works fine with jdk 1.5 and former versions.
This happens only when we pass single digit in Date/Month parameter. (As in above example "1" is passed as month parameter instead of "01")
*Is anyone knows about the issue and the workaround for this?* *Please post your comment on this issue.....*
You can see the source code of the valueOf method to see how it parses the string date and constructs the timestamp object.
To avoid such problem, you could parse your string first then construct a java.util.Calendar object using the int values you've got after the parsing.
You can then create a Timestamp object using new Timestamp(myCalendar.getTime().getTime())...