Where is the date format specified when reading the date as a string from JDBC ResultSet

This is exactly the same question as the JDBC default date format when reading a date as a string from a ResultSet , but this question has never been answered as such; people just suggested alternative ways of writing code.

I specifically ask if anyone knows where the default conversion format is indicated, and if it is defined by the JDBC specification somewhere or just stayed up to a separate JDBC driver. If the latter, then the question is, how does Oracle 10g JDBC do this?

** Added January 15th:

Sorry, I thought the question was clear enough, but apparently not. I am not trying to get the date value from the database and do not need suggestions on how to do this.

I do not think this is a duplicate of the question mentioned, so I asked a separate question here. Although the title is pretty much the same, the above question (no matter what the OP intended) was given an alternative approach for getting the date value from the database, which I don't want to know.

Greetings

+2
source share
3 answers

Well, therefore, while tracking JDBC code, it seems that the Oracle driver is hard-coded for its own formatting:

int k = (((bytes[0 + j] & 255) - 100) * 100 + (bytes[1 + j] & 255)) - 100; String s = k + "-" + toStr(bytes[2 + j]) + "-" + toStr(bytes[3 + j]) + " " + toStr(bytes[4 + j] - 1) + ":" + toStr(bytes[5 + j] - 1) + ":" + toStr(bytes[6 + j] - 1) + ".0"; 

So, I assume that:

  • This behavior is not specified anywhere in the JDBC specification.
  • Each driver library can return any format that it likes.

I guess this is because different implementations return different formats. Of course, it is still possible that this format is specified somewhere in the JDBC specification, and some implementations are inconsistent, but this seems unlikely. I definitely could not find references to this in the JDBC specification (but that does not mean that they are not somewhere).

However, the key point, as far as I know, is that the format is hard-coded in the library and is not overridden by any environments or other settings, but will also not be changed on different systems if the driver library version remains the same.

+1
source

Oracle 10g JDBC is closed, so I think we will never know :), but I'm sure that it first requests the server for locale information and, in accordance with the server settings, it sets up the internal data format that it will use. My 2c.

0
source

I am not 100% sure of all database implementations for the SQL Date type. But from the javadoc of the Oracle database, it seems that Oracle DB DATE can be easily converted to java.sql.Date . The same is true for MySQL and PostgreSQL : SQL DATE can be converted to java.sql.Date .

0
source

All Articles