db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Army <a...@golux.com>
Subject Date formatting with Network Server
Date Fri, 14 Jan 2005 01:22:45 GMT
Question regarding date formatting in the Network Server:


With a Sun JVM, the above line will print "0001-01-01".  With an IBM JVM, it will print "1-01-01".
 The difference is 
apparently in the implementation of the "toString()" method for the two JVMs.

Currently, when a query against Network Server returns a date column, the string value for
that column is returned using 
the following line (in DRDAConnThread.java):

	writer.writeString(((java.sql.Date) val).toString());

This works fine for Sun JVM, because the toString() method returns "0001-01-01".  However,
for IBM JVM, the string 
"1-01-01" is returned, and that causes the JDBC client to fail, presumably because the client
sees it as an invalid date 

This is reproduced easily enough; start the server with an IBM JVM, connect to it using ij,
insert the value 
"0001-01-01" into a table, then select from the table.  You'll get an error.

So my question is three-fold:

1) The Java definition for java.sql.Date.toString() says: "Formats a date in the date escape
format yyyy-mm-dd".  So as 
far as I can tell, this means that, with the current implementation, the format yyyy-mm-dd
will always be used, 
regardless of locale.  Is that right?  And is that _acceptable_??

2) If the answer to #1 is "Yes", then is it safe to replace the "writeString" call above with
the following?

	SimpleDateFormat df = new java.text.SimpleDateFormat("yyyy-MM-dd");
	writer.writeString(df.format((java.sql.Date) val));

Or is there some reason why we need to avoid using SimpleDateFormat?

3) I noticed some DateFormat code in the engn, for Derby embedded.  Should Network Server
just be using that somehow, 
instead of doing a different thing here?



View raw message