FileDocCategorySizeDatePackage
ResultSetTable.javaAPI DocExample1863Thu Apr 05 20:33:10 BST 2001None

ResultSetTable

public class ResultSetTable extends Table

Fields Summary
Constructors Summary
public ResultSetTable(ResultSet rs)

    this(rs, null);
  
public ResultSetTable(ResultSet rs, TableCustomizer[] customizers)

    setBorder(1);

    if (customizers == null) {
      customizers = new TableCustomizer[0];
    }

    ResultSetMetaData rsmd = rs.getMetaData();
    int colCount = rsmd.getColumnCount();

    TR row = new TR();
    for (int i = 1; i <= colCount; i++) {
      addElement(new TH().addElement(rsmd.getColumnName(i)));
    }
    addElement(row);

    while (rs.next()) {
      row = new TR();
      for (int i = 1; i <= colCount; i++) {
        TD td = new TD();
        int columnType = rsmd.getColumnType(i);
        String columnTypeName = rsmd.getColumnTypeName(i);
        String columnName = rsmd.getColumnName(i);

        // Give each customizer a chance to control output
        boolean customized = false;
        for (int c = 0; c < customizers.length; c++) {
          TableCustomizer customizer = customizers[c];
          if (customizer.accept(columnType, columnTypeName,
                                columnName, rs, i)) {
            td.addElement(customizer.display(columnType, columnTypeName,
                                             columnName, rs, i));
            customized = true;
            break;
          }
        }

        // If no customizer wanted the job, display the value as a String
        if (!customized) {
          td.addElement(rs.getString(i));
        }

        addElement(td);
      }
      addElement(row);
    }
  
Methods Summary