It’s a life we live, that’s what’s important in this life I think, it’s the best possible outcome at least. If we don’t understand that much about life, then what are we supposed to do about it? I mean, come on now. We’re meant to live and see what’s out there, aren’t we? One would think so! If we can’t do that, then we’re lost souls on this river, or ocean even and we cannot get past it all. We are lost at sea as it were cast about the waves unable to get past whatever it is we’re meant to get past. So, let’s live life to its fullest. Don’t overthink things, don’t allow yourself to become corrupt in such thinking. Supposedly not everything is black and white, I’m not sure how that works exactly. I wish I could have a handle on it all, but I don’t know how that tends to work. So I forget whatever is meant to be and I will understand it as it’s meant to come to me, if at all.
Every once in a while we need to populate data in a JTable. Here's a simple to use DefaultTableModel for populating a JTable from a ResultSet.
public DefaultTableModel buildTableModel(ResultSet rs)
throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
Vector columnNames = new Vector<String>();
int columnCount = metaData.getColumnCount();
for (int column = 1; column <= columnCount; column++) {
columnNames.add(metaData.getColumnName(column));
}
Vector<Vector<Object>> data = new Vector<Vector<Object>>();
while (rs.next()) {
Vector<Object> vector = new Vector<Object>();
for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) {
vector.add(rs.getObject(columnIndex));
}
data.add(vector);
}
DefaultTableModel dtm = new DefaultTableModel(data, columnNames) {
private static final long serialVersionUID = 1L;
@Override
public boolean isCellEditable(int row, int column) {
//all cells false
return false;
}
};
return dtm;
}
Comments
Post a Comment