participate


Java Runtime Environment (JRE) - Issue with TimeStamp.valueOf method of JDK 1.6
<<   Back to Forum  |   Give us Feedback
This topic has 1 reply on 1 page.
gladwin
Posts:2
Registered: 10/14/08
Issue with TimeStamp.valueOf method of JDK 1.6   
Oct 14, 2008 4:48 AM

 
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.....*
 
java_2006
Posts:1,978
Registered: 1/20/06
Re: Issue with TimeStamp.valueOf method of JDK 1.6   
Oct 14, 2008 6:04 AM (reply 1 of 1)  (In reply to original post )

 
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())...

hope it helps
 
This topic has 1 reply on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 28
  • Guests : 129

About Sun forums
  • Oracle Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Oracle Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums