2014-10-06 61 views
1

我試圖從數據庫表中加載記錄到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

回答

2

首先通過ResultSet

int itemId=1; 
while(rs.next()){ 
    table.addItem(new Object[]{rs.getLong("id"),rs.getString("name")},itemId++); 
} 
+1

做得好添加容器性能

table.addContainerProperty("Id", Long.class, 1L); table.addContainerProperty("Name", String.class, ""); //...... //Add other columns for table which are container properties 

循環!完美的作品 – ilovkatie 2014-10-06 13:18:42

相關問題