JDBC getColumns differences between "IS_NULLABLE" and "NULLABLE"

I am trying to extract the JDBC database driver database metadata.

And now I come across a piece of documentation that I cannot explain to myself:

Method DatabaseMetaData.getColumns(...); ( JavaDoc ) contains two different nullability columns:

  NULLABLE int => is NULL allowed.
     columnNoNulls - might not allow NULL values
     columnNullable - definitely allows NULL values
     columnNullableUnknown - nullability unknown 

and

  IS_NULLABLE String => ISO rules are used to determine the nullability for a column.
     YES --- if the column can include NULLs
     NO --- if the column cannot include NULLs
     empty string --- if the nullability for the column is unknown 

The only idea I could think of for two different columns:

The one that defines the table column may be null when reading, and other states that can be inserted into this table column. But I could not determine the correctness of this idea.

Does anyone know for sure what the difference is between the two columns? Is there more details about this part of the JDBC API?

Thanks for the help.

+5
source share
1 answer

As far as I know, the value is the same, however IS_NULLABLE follows the definition of the information_schema.columns view from SQL: 2011 Schemata (ISO-9075-11: 2011), although SQL: 2011 does not indicate the value of the empty string (it indicates only NO if it not equal to NULL, and YES for all other cases). The NULLABLE column uses the values โ€‹โ€‹of the constants columnNoNulls , columnNullable and columnNullableUnknown , which can be used for more readable code, and for use in switch (which pre-Java 7 did not support the row). This is also equivalent to the return value of ResultSetMetaData.isNullable(int) .

In general, the definition of metadata result sets is based on tables and information_schema views defined in ISO-9075-11: 2011 (SQL: 2011 Schemata) or other versions of the SQL standard. This specification can be used to obtain additional column information, with the exception of special JDBC add-ons. These add-ons are usually not explicitly indicated except in javadoc (and by reading between the lines in other parts of apidoc and the specification), although these add-ons usually follow the rules and logic of the SQL standard.

+3
source

Source: https://habr.com/ru/post/1205195/


All Articles