我正在尝试将记录从数据库表加载到Vaadin表。
我从表process
获取所有记录,如下所示:
public ResultSet selectRecordsFromDbUserTable() throws SQLException {
Connection dbConnection = null;
Statement statement = null;
ResultSet rs = null;
String selectTableSQL = "SELECT * from process";
try {
dbConnection = getDBConnection();
statement = dbConnection.createStatement();
System.out.println(selectTableSQL);
// execute select SQL stetement
rs = statement.executeQuery(selectTableSQL);
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
if (statement != null) {
statement.close();
}
if (dbConnection != null) {
dbConnection.close();
}
}
return rs;
}
它运作良好。在ResultSet rs
我得到了我需要的所有行。
如何将它们加载到Vaadin Table
?
答案 0 :(得分:2)
首先添加容器属性
table.addContainerProperty("Id", Long.class, 1L);
table.addContainerProperty("Name", String.class, "");
//......
//Add other columns for table which are container properties
循环浏览ResultSet
int itemId=1;
while(rs.next()){
table.addItem(new Object[]{rs.getLong("id"),rs.getString("name")},itemId++);
}