ResultSetMetaData.columnNullableUnknown : ResultSetMetaData « java.sql « Java by API






ResultSetMetaData.columnNullableUnknown

 

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

public class Main {
  private static final String DRIVER = "com.mysql.jdbc.Driver";

  private static final String URL = "jdbc:mysql://localhost/testdb";

  private static final String USERNAME = "root";

  private static final String PASSWORD = "";

  public static void main(String[] args) throws Exception {
    Class.forName(DRIVER);
    Connection connection = DriverManager.getConnection(URL, USERNAME, PASSWORD);

    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery("SELECT id, username FROM users");
    ResultSetMetaData metadata = resultSet.getMetaData();
    int nullability = metadata.isNullable(1);

    if (nullability == ResultSetMetaData.columnNullable) {
      System.out.println("Columns ID can have a null value");
    } else if (nullability == ResultSetMetaData.columnNoNulls) {
      System.out.println("Columns ID does not allowed to have a null value");
    } else if (nullability == ResultSetMetaData.columnNullableUnknown) {
      System.out.println("Nullability unknown");
    }
  }
}

   
  








Related examples in the same category

1.ResultSetMetaData.columnNoNulls
2.ResultSetMetaData.columnNullable
3.ResultSetMetaData: getCatalogName(int column)
4.ResultSetMetaData: getColumnCount()
5.ResultSetMetaData: getColumnDisplaySize(int column)
6.ResultSetMetaData: getColumnClassName(int column)
7.ResultSetMetaData: getColumnLabel(int column)
8.ResultSetMetaData: getColumnName(int column)
9.ResultSetMetaData: getColumnType(int column)
10.ResultSetMetaData: getPrecision(int column)
11.ResultSetMetaData: getScale(int column)
12.ResultSetMetaData: getSchemaName(int column)
13.ResultSetMetaData: getTableName(int column)
14.ResultSetMetaData: isAutoIncrement(int column)
15.ResultSetMetaData: isCaseSensitive(int column)
16.ResultSetMetaData: isCurrency(int column)
17.ResultSetMetaData: isDefinitelyWritable(int column)
18.ResultSetMetaData: isNullable(int column)
19.ResultSetMetaData: isReadOnly(int column)
20.ResultSetMetaData: isSearchable(int column)
21.ResultSetMetaData: isSigned(int column)
22.ResultSetMetaData: isWritable(int column)