On 02/23/2011 11:42 AM, Mike Fowler wrote:
> Hi all,
>
> I have just pulled out the source from CVS and run the build and test and
> found a failure in the class noted in the subject. Specifically the test that
> fails is:
>
> 79 public void testSetDate() throws SQLException
> 80 {
> ...
> 111 ps.setObject(1, "1969-04-3", java.sql.Types.DATE);
> 112 assertEquals(1, ps.executeUpdate());
> ...
> 120 ps.setObject(1, java.sql.Date.valueOf("1912-5-1"), java.sql.Types.DATE);
> 121 assertEquals(1, ps.executeUpdate());
> ...
>
> This only fails in my JDK 1.6 - it passes in 1.5. Looking at the java.sql.Date
> in the two source jars I have it's easy to see that the valueOf method has
> been completely rewritten in 1.6 (well, at least 1.6.0_21 possibly earlier).
> Having looked at the API documentation has remained unchanged in 1.3, 1.4, 1.5
> and 1.6 (1.2 I couldn't find by guessing) and reads:
>
> * @param s a <code>String</code> object representing a date in
> * in the format "yyyy-mm-dd"
The Java 7 docs say:
"s - a String object representing a date in in the format "yyyy-[m]m-[d]d".
The leading zero for mm and dd may also be omitted."
http://download.oracle.com/javase/7/docs/api/java/sql/Date.html
So the java.sql.Date does accept single-digit month and day, at least for Java 7.
All the work you did to reject single-digit month and day are not correct, if
that's what you did.
--
Lew
Honi soit qui mal y pense.