Wrong Datatype for NVARCHAR Column in JDBC 11.1

(Doc ID 1608044.1)

Last updated on MARCH 08, 2017

Applies to:

JDBC - Version 11.1.0.6 to 11.1.0.7 [Release 11.1]
Information in this document applies to any platform.

Symptoms

Java™ Platform Standard Ed. 6 (http://docs.oracle.com/javase/6/docs/api/constant-values.html#java.sql.Types.BIT) shows the following java.sql.Types for VARCHAR and NVARCHAR datatypes:

public static final int NVARCHAR -9
...
public static final int VARCHAR 12

  

 With JDBC 11.2, this is the case. However, with JDBC 11.1 VARCHAR (column type 12) is returned for  NVARCHAR.

 

Steps to reproduce the issue:

1. Create the following table:

SQL> desc TestTable
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------
ID                                                    NUMBER(20)
TEXT1                                             NVARCHAR2(10)
TEXT2                                             VARCHAR2(10)


2. Create the following program to get the column types:

  


Testing with JDBC 11..10.1 ojjdbc6.jar and JDK 1.6.:


D:\software\jdbc_drivers\11.1.0.7>java MetaDataTest
Connecting with:
jdbc:oracle:thin:@rmoussal-us2.us.oracle.com:1521:soa
DriverVersion:      [11.1.0.7.0-Production]
DriverMajorVersion: [11]
DriverMinorVersion: [1]
DriverName:         [Oracle JDBC driver]
Meta data retrieved ...

Column [1] ...
      ColumnName:ID
ColumnDisplaySize:22
    ColumbnLabel:ID
 ColumnClassName:java.math.BigDecimal
      ColumnType:2
  ColumnTypeName:NUMBER
           Scale:0
       Precision:20
        Nullable:1
   CaseSensitive:false

Column [2] ...
      ColumnName:TEXT1
ColumnDisplaySize:10
    ColumbnLabel:TEXT1
 ColumnClassName:java.lang.String
      ColumnType:12                                  <------------------------Column Type = 12
  ColumnTypeName:VARCHAR2
           Scale:0
       Precision:10
        Nullable:1
   CaseSensitive:true

Column [3] ...
      ColumnName:TEXT2
ColumnDisplaySize:10
    ColumbnLabel:TEXT2
 ColumnClassName:java.lang.String
      ColumnType:12
  ColumnTypeName:VARCHAR2
           Scale:0
       Precision:10
        Nullable:1
   CaseSensitive:true
Done.



- Testing with JDBC 11.2.0.4 or higher and JDK 1.6:

D:\software\jdbc_drivers\11.2.0.4>java MetaDataTest
Connecting with:
jdbc:oracle:thin:@rmoussal-us2.us.oracle.com:1521:soa
DriverVersion:      [11.2.0.3.0]
DriverMajorVersion: [11]
DriverMinorVersion: [2]
DriverName:         [Oracle JDBC driver]
Meta data retrieved ...

Column [1] ...
      ColumnName:ID
ColumnDisplaySize:21
    ColumbnLabel:ID
 ColumnClassName:java.math.BigDecimal
      ColumnType:2
  ColumnTypeName:NUMBER
           Scale:0
       Precision:20
        Nullable:1
   CaseSensitive:false

Column [2] ...
      ColumnName:TEXT1
ColumnDisplaySize:10
    ColumbnLabel:TEXT1
 ColumnClassName:java.lang.String
      ColumnType:-9                                    <----------------------------------Column type = -9
  ColumnTypeName:NVARCHAR2
           Scale:0
       Precision:10
        Nullable:1
   CaseSensitive:true

Column [3] ...
      ColumnName:TEXT2
ColumnDisplaySize:10
    ColumbnLabel:TEXT2
 ColumnClassName:java.lang.String
      ColumnType:12
  ColumnTypeName:VARCHAR2
           Scale:0
       Precision:10
        Nullable:1
   CaseSensitive:true
Done.



Changes

 Upgrade from JDBC 11.1 to JDBC 11.2 or higher

Cause

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms