This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 246547 - DatabaseMetaData returns wrong datatype for Oracle's NVARCHAR2
Summary: DatabaseMetaData returns wrong datatype for Oracle's NVARCHAR2
Status: RESOLVED INVALID
Alias: None
Product: db
Classification: Unclassified
Component: Code (show other bugs)
Version: 8.0
Hardware: PC All
: P3 normal (vote)
Assignee: Libor Fischmeistr
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-19 11:57 UTC by cstadler
Modified: 2014-08-20 05:32 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cstadler 2014-08-19 11:57:38 UTC
I'am using JDBC 12.1.0.1.0 with Oracle 11g on Netbeans 8.0.

The method java.sql.DatabaseMetaData#getColumns(...) return the type OTHER instead of NVARCHAR2.
In Combination with org.netbeans.modules.db.metadata.model.MetadataUtilities#getColumns(...) this SQL-Code will be generated:

SELECT  NULL AS table_cat,
       t.owner AS table_schem,
       t.table_name AS table_name,
       t.column_name AS column_name,
       DECODE (t.data_type, 'CHAR', 1, 'VARCHAR2', 12, 'NUMBER', 3,
               'LONG', -1, 'DATE', 93, 'RAW', -3, 'LONG RAW', -4,  
               'BLOB', 2004, 'CLOB', 2005, 'BFILE', -13, 'FLOAT', 6, 
               'TIMESTAMP(6)', 93, 'TIMESTAMP(6) WITH TIME ZONE', -101, 
               'TIMESTAMP(6) WITH LOCAL TIME ZONE', -102, 
               'INTERVAL YEAR(2) TO MONTH', -103, 
               'INTERVAL DAY(2) TO SECOND(6)', -104, 
               'BINARY_FLOAT', 100, 'BINARY_DOUBLE', 101, 
               'XMLTYPE', 2009, 
               1111)
              AS data_type,
       t.data_type AS type_name,
       DECODE (t.data_precision,                null, DECODE(t.data_type,                        'NUMBER', DECODE(t.data_scale,                                    null, 0                                   , 38),          DECODE (t.data_type, 'CHAR', t.char_length,                   'VARCHAR', t.char_length,                   'VARCHAR2', t.char_length,                   'NVARCHAR2', t.char_length,                   'NCHAR', t.char_length,                   'NUMBER', 0,           t.data_length)                           ),         t.data_precision)
              AS column_size,
       0 AS buffer_length,
       DECODE (t.data_type,                'NUMBER', DECODE(t.data_precision,                                 null, DECODE(t.data_scale,                                              null, -127                                             , t.data_scale),                                  t.data_scale),                t.data_scale) AS decimal_digits,
       10 AS num_prec_radix,
       DECODE (t.nullable, 'N', 0, 1) AS nullable,
       NULL AS remarks,
       t.data_default AS column_def,
       0 AS sql_data_type,
       0 AS sql_datetime_sub,
       t.data_length AS char_octet_length,
       t.column_id AS ordinal_position,
       DECODE (t.nullable, 'N', 'NO', 'YES') AS is_nullable,
         null as SCOPE_CATALOG,
       null as SCOPE_SCHEMA,
       null as SCOPE_TABLE,
       null as SOURCE_DATA_TYPE,
       'NO' as IS_AUTOINCREMENT
FROM all_tab_columns t
WHERE t.owner LIKE :1 ESCAPE '/'
  AND t.table_name LIKE :2 ESCAPE '/'
  AND t.column_name LIKE :3 ESCAPE '/'

ORDER BY table_schem, table_name, ordinal_position


In lines 5 to 14 there is a datatype mapping. All type are not in this list will have the type OTHER (1111).
How can i extend this list or how can i change this behavior to get the real datatypes ?
Comment 1 matthias42 2014-08-19 12:48:22 UTC
(In reply to cstadler from comment #0)
> I'am using JDBC 12.1.0.1.0 with Oracle 11g on Netbeans 8.0.
> 
> The method java.sql.DatabaseMetaData#getColumns(...) return the type OTHER
> instead of NVARCHAR2.
> In Combination with
> org.netbeans.modules.db.metadata.model.MetadataUtilities#getColumns(...)
> this SQL-Code will be generated:
> 
> [SQL executed]
> 
> 
> In lines 5 to 14 there is a datatype mapping. All type are not in this list
> will have the type OTHER (1111).
> How can i extend this list or how can i change this behavior to get the real
> datatypes ?

You have to contact oracle (the database branch) - what you see is generated by their own JDBC driver implementation - org.netbeans.modules.db.metadata.model.MetadataUtilities#getColumns is just a _very_ thin wrapper around getColumns. DatabaseMetaData has to be implemented by the driver vendor (in this case oracle) and it seems they missed their own datatypes.

Having said that: You can workaround oracle in this case: check first the SQL-Type as you do now, if this is OTHER, than check typeName this should give you the "real" DB type.

Closing this as INVALID as the problem is inside the JDBC driver.
Comment 2 cstadler 2014-08-20 05:32:18 UTC
Thanks