Search code examples
javajdbcresultset

Can ResultSetMetaData.getColumnLabel return null?


My question is can, ResultSetMetaData.getColumnLabel(int) return null ?

Is there any known cases where any of the driver implementation return null ? If so, how to achieve that case.

From documentation, it seems there is no such restriction. I want a second opinion regarding this.

Update 1:

In PostgreSQL, when I execute a simple query select 1;, the returned column name ?column?. My question is, are there any scenarios where column label can be null.


Solution

  • The JDBC API doesn't explicitly forbid null as a value for getColumnLabel (or getColumnName), so it not impossible that there are JDBC implementations that return null for unnamed columns.

    That said, I can't think of examples of the top of my head. As far as I'm aware, most databases generate a default label for unnamed columns.