Sunday, July 3, 2011

Implementing getColumnAt

The getColumnAt method retrieves the value at the specified row and column in the row set coffeesRowSet. The JTable class uses this method to populate its table. Note that SQL starts numbering its rows and columns at 1, but the TableModel interface starts at 0; this is the reason why the rowIndex andcolumnIndex values are incremented by 1.

  public Object getValueAt(int rowIndex, int columnIndex) {      try {       this.coffeesRowSet.absolute(rowIndex + 1);       Object o = this.coffeesRowSet.getObject(columnIndex + 1);       if (o == null)         return null;       else         return o.toString();     } catch (SQLException e) {       return e.toString();     }   }

No comments:

Post a Comment