ベクトルからのデータが取り込まれた JTable があり、データの編集後にデータベースに自動保存したいと考えています。
Vector columnNames = new Vector();
Vector data = new Vector();
Connection conn = dbConnect.connect();
String sql = "Select date, frequency, type, payeereceivee, amount, comments from schedule where date ='" + outputdate + "'";
Statement statement = conn.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
ResultSetMetaData metaData = resultSet.getMetaData();
int columns = metaData.getColumnCount();
for (int i = 1; i <= columns; i++) {
columnNames.addElement(metaData.getColumnName(i));
}
while (resultSet.next()) {
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++) {
row.addElement(resultSet.getObject(i));
}
data.addElement(row);
}
resultSet.close();
statement.close();
tbl = new JTable(data, columnNames);
TableColumn column;
for (int i = 0; i < tbl.getColumnCount(); i++) {
column = tbl.getColumnModel().getColumn(i);
column.setMaxWidth(250);
}