2014-10-06 58 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

相关问题