Java Code Examples for java.sql.ResultSetMetaData#isWritable()

The following examples show how to use java.sql.ResultSetMetaData#isWritable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreparedStatementTest.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
boolean isEqualsTo(ResultSetMetaData metadata, int colNum) throws SQLException {
  return
      metadata.getCatalogName(colNum).equals(InfoSchemaConstants.IS_CATALOG_NAME) &&
      metadata.getSchemaName(colNum).isEmpty() &&
      metadata.getTableName(colNum).isEmpty() &&
      metadata.getColumnName(colNum).equals(columnName) &&
      metadata.getColumnLabel(colNum).equals(columnName) &&
      metadata.getColumnType(colNum) == type &&
      metadata.isNullable(colNum) == nullable &&
      // There is an existing bug where query results doesn't contain the precision for VARCHAR field.
      //metadata.getPrecision(colNum) == precision &&
      metadata.getScale(colNum) == scale &&
      metadata.isSigned(colNum) == signed &&
      metadata.getColumnDisplaySize(colNum) == displaySize &&
      metadata.getColumnClassName(colNum).equals(className) &&
      metadata.isSearchable(colNum) &&
      metadata.isAutoIncrement(colNum) == false &&
      metadata.isCaseSensitive(colNum) == false &&
      metadata.isReadOnly(colNum) &&
      metadata.isWritable(colNum) == false &&
      metadata.isDefinitelyWritable(colNum) == false &&
      metadata.isCurrency(colNum) == false;
}
 
Example 2
Source File: SelectStatementsTester.java    From spanner-jdbc with MIT License 5 votes vote down vote up
private void testSelect(String sql, Object... parameters) throws SQLException {
  PreparedStatement ps = connection.prepareStatement(sql);
  for (int i = 1; i <= parameters.length; i++) {
    ps.setObject(i, parameters[i - 1]);
  }
  try (ResultSet rs = ps.executeQuery()) {
    ResultSetMetaData metadata = rs.getMetaData();
    for (int i = 1; i <= metadata.getColumnCount(); i++) {
      metadata.getColumnClassName(i);
      metadata.getColumnDisplaySize(i);
      metadata.getColumnLabel(i);
      metadata.getColumnName(i);
      metadata.getColumnType(i);
      metadata.getColumnTypeName(i);
      metadata.getPrecision(i);
      metadata.getScale(i);
      metadata.getCatalogName(i);
      metadata.getSchemaName(i);
      metadata.getTableName(i);
      metadata.isNullable(i);
      metadata.isAutoIncrement(i);
      metadata.isCaseSensitive(i);
      metadata.isCurrency(i);
      metadata.isDefinitelyWritable(i);
      metadata.isReadOnly(i);
      metadata.isSearchable(i);
      metadata.isSigned(i);
      metadata.isWritable(i);
    }
    while (rs.next()) {
      // do nothing
    }
  }
}
 
Example 3
Source File: ResultSetLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException {
    int columnCount = 0;
    try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
        ResultSetMetaData metaData = rs.getMetaData();
        columnCount = metaData.getColumnCount();
        for (int i = 1; i <= columnCount; i++) {
            String catalogName = metaData.getCatalogName(i);
            String className = metaData.getColumnClassName(i);
            String label = metaData.getColumnLabel(i);
            String name = metaData.getColumnName(i);
            String typeName = metaData.getColumnTypeName(i);
            Integer type = metaData.getColumnType(i);
            String tableName = metaData.getTableName(i);
            String schemaName = metaData.getSchemaName(i);
            boolean isAutoIncrement = metaData.isAutoIncrement(i);
            boolean isCaseSensitive = metaData.isCaseSensitive(i);
            boolean isCurrency = metaData.isCurrency(i);
            boolean isDefiniteWritable = metaData.isDefinitelyWritable(i);
            boolean isReadOnly = metaData.isReadOnly(i);
            boolean isSearchable = metaData.isSearchable(i);
            boolean isReadable = metaData.isReadOnly(i);
            boolean isSigned = metaData.isSigned(i);
            boolean isWritable = metaData.isWritable(i);
            int nullable = metaData.isNullable(i);
        }
    }

    assertEquals("column count", 4, columnCount);
}