0

I am facing a strange kind of scenario. I have the following table, with two columns.

Customer:

Customer_ID nvarchar2
Subscription_Date Date

I am trying to get the column type of Subscription_Date using Meta Data as shown below:

ResultSet rs = selectStmt.executeQuery("SELECT Customer_ID, Subscription_Date FROM Cusomter");
java.sql.ResultSetMetaData rsMetaData = rs.getMetaData();
int type1 = rsMetaData.getColumnType(2);

If I use JDK 1.6 and ojdbc6.jar, type1 is returned as

93 (java.sql.Types.TIMESTAMP)

If I use JDK 1.5 and ojdbc14.jar, type1 is returned as

91 (java.sql.Types.DATE)

But in both the scenarios, the actual column type of Subscription_Date is DATE. Is this some backward compatability issue? Or is my way of coding is wrong? Can you guys please look into it and provide some suggestion?

Gokul Nath KP
  • 15,485
  • 24
  • 88
  • 126
  • 1
    Read the release notes for the driver, this is documented. The new behaviour is correct (because the old driver would "remove" the time part from a `DATE` column) –  Mar 28 '13 at 14:55
  • So if I wanted to support both ojdbc14 with JDK 1.5 and ojdbc6 with JDK 1.6, how should I proceed...?? – Gokul Nath KP Apr 03 '13 at 10:34
  • 1
    If you need to support JDK 1.5 you should use `ojdbc5.jar` (which would work on Java 6 as well). –  Apr 03 '13 at 10:38

1 Answers1

3

The oracle datatype of DATE is identical to the SQL standards (and JDBC) concept of TIMESTAMP as it stores date + time. The SQL standards concept of DATE only stores a date (so year, month, day in month). The behavior in ojdbc6.jar is correct and ojdbc14.jar was wrong.

Not all relational database servers use the exact same names for things. The SQL standards did not emerge until after there were relational databases, and some (or most) kept using their legacy naming for datatypes instead of moving to the names of the standards.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197