0

The Java 7 Javadoc for DatabaseMetaData.getColumns() says it returns a ResultSet with 24 columns, the first named TABLE_CAT and the last named IS_GENERATEDCOLUMN. However, the result set I receive from Oracle has only 18 columns. I verified it with the following code:

DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet set = databaseMetaData.getColumns(catalogName, schemaPattern,
        tableNamePattern, columnNamePattern);
final ResultSetMetaData resultSetData = set.getMetaData();
final int columnCount = resultSetData.getColumnCount();

for (int columnIndex = 1; columnIndex <= columnCount; ++columnIndex) {
   final String columnName = resultSetData.getColumnName(columnIndex);
   System.out.printf("Column %d: %s%n", columnIndex, columnName);
}

The above code produces this output:

Column 1: TABLE_CAT
Column 2: TABLE_SCHEM
Column 3: TABLE_NAME
Column 4: COLUMN_NAME
Column 5: DATA_TYPE
Column 6: TYPE_NAME
Column 7: COLUMN_SIZE
Column 8: BUFFER_LENGTH
Column 9: DECIMAL_DIGITS
Column 10: NUM_PREC_RADIX
Column 11: NULLABLE
Column 12: REMARKS
Column 13: COLUMN_DEF
Column 14: SQL_DATA_TYPE
Column 15: SQL_DATETIME_SUB
Column 16: CHAR_OCTET_LENGTH
Column 17: ORDINAL_POSITION
Column 18: IS_NULLABLE

Why don't I get all 24 columns? What am I missing?

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • 1
    *What am I missing?*: I'd say: a JDBC driver that respects the specifications. – JB Nizet Sep 19 '16 at 16:53
  • 1
    Oracle are known for their faithful implementation of JDBC specs. – mustaccio Sep 19 '16 at 20:18
  • First of all you can simply print the columnCount to check the number of rows returned. Secondly you can check the `databaseMetaData.getColumns(catalogName, schemaPattern, tableNamePattern, columnNamePattern);` if your **catalogName , columnNamePattern , tableNamePattern , schemaPattern** matches all the 24 columns or just the 18 - hope this helps – Patrick Sep 19 '16 at 22:55
  • The procedure you describe is exactly what I did. However I get a column count of 18 instead of 24. Is it possible I need a different Oracle driver? I'm running Java 7, with this driver: com.oracle ojdbc14 10.2.0.4.0 jar runtime – Adam Richards Sep 20 '16 at 12:01

0 Answers0