将所有记录从数据库获取到Vaadin表

时间:2014-10-06 12:25:07

标签: java postgresql vaadin

我正在尝试将记录从数据库表加载到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

1 个答案:

答案 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++);
}
相关问题