Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top