1

I am using ResultSetMetadata.getColumnDisplaySize to get the column display size but it always returns zero. What can be the reason for that. Is there an alternative way to get the correct size? thanks.

private List<Column> getColumns(ResultSet rs) throws SQLException {
        List<Column> columns = new ArrayList<>();
        ResultSetMetaData md = rs.getMetaData();
        int columnCount = md.getColumnCount();

        for(int i =1; i<= columnCount; i++) {
            Column column = new Column();
            column.setName(md.getColumnLabel(i));
            column.setDataType(md.getColumnTypeName(i));
            column.setSize(md.getColumnDisplaySize(i));
            columns.add(column);
        }

        return columns;
    }
whb
  • 661
  • 2
  • 10
  • 22
  • Which database are you using ? – Tunaki Feb 16 '15 at 22:23
  • tried in oracle and mysql – whb Feb 16 '15 at 22:31
  • 2
    Drivers sometimes return 0 when they simply don't know how to return a proper size. What is the type of the database column ? – Tunaki Feb 16 '15 at 22:41
  • Does your table have any data in it? I recall having problems like this for tables without data. – Astra Bear Feb 16 '15 at 22:41
  • they are number, date and varchar2. btw there is a similar discussion in https://groups.google.com/forum/#!topic/h2-database/Gjwkqo095ew. I do have data but i do not iterate with resultset. I just want to get metadata. – whb Feb 16 '15 at 22:44

0 Answers0