One of the jobs of OJDBC is to map Oracle data types to Java types.
However, we noticed that if we give a CHAR
data type, it is not mapped to java.lang.String
. The versions showing this behavior are: OJDBC7 v12.1.0.2 and OJDBC6 v12.1.0.1. The older versions did indeed map the CHAR
data type to: java.lang.String
.
On digging deeper, we discovered that there is a class: StructMetaData
within the oracle.jdbc.driver
package of OJDBC that implements the Oracle data type to Java Type mapping. There is a method within it: 'getColumnClassName(int arg0)' that is worthy of attention. We noticed that for OJDBC v7, the cases mapped to java.lang.String
are as follows:
int arg1 = this.getColumnType(arg0);
switch (arg1) {
case -104:
return "oracle.sql.INTERVALDS";
case -103:
return "oracle.sql.INTERVALYM";
case -102:
return "oracle.sql.TIMESTAMPLTZ";
case -101:
return "oracle.sql.TIMESTAMPTZ";
case -15:
case -9:
case 12:
return "java.lang.String";
...
However, within older OJDBC implementations, it looked like this:
int arg1 = this.getColumnType(arg0);
switch (arg1) {
case -104:
return "oracle.sql.INTERVALDS";
case -103:
return "oracle.sql.INTERVALYM";
case -102:
return "oracle.sql.TIMESTAMPLTZ";
case -101:
return "oracle.sql.TIMESTAMPTZ";
case -15:
case -9:
case 1:
case 12:
return "java.lang.String";
...
There is an additional case mapped to java.lang.String
in the latter case viz. 'case 1'. This 'case 1' is not mapped to java.lang.String
in the first code snippet shown above.
On looking deeper, this 'case 1' is mapped to CHAR
within the getColumnTypeName(int arg0 )
method of the same StructMetaData
class:
public String getColumnTypeName(int arg0) throws SQLException {
int arg1 = this.getColumnType(arg0);
int arg2 = this.getValidColumnIndex(arg0);
switch (arg1) {
case -104:
return "INTERVALDS";
case -103:
return "INTERVALYM";
case -102:
return "TIMESTAMP WITH LOCAL TIME ZONE";
case -101:
return "TIMESTAMP WITH TIME ZONE";
case -15:
return "NCHAR";
case -13:
return "BFILE";
case -9:
return "NVARCHAR";
case -2:
return "RAW";
case 1:
return "CHAR";
...
Because of this, if we use OJDBC 7 or OJDBC6 v12.1.0.1 and specify CHAR
as the data type for a column, the following code returns null
on invocation for this column's index:
for (int i = 1; i <= resultSetMetaData.getColumnCount(); i++) {
...
resultSetMetaData.getColumnClassName(columnIndex)
...
If I replace an older version of the OJDBC jar (for example: 11.2.0.3), then the same code returns: java.lang.String
. Is this a bug or was it removed by design?
Has anybody faced the same issue before?