ilovkatie ilovkatie - 1 year ago 174
Java Question

Getting all records from database to Vaadin Table

I'm trying to load records from database table to Vaadin table.

I'm getting all records from table

like this:

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();
// execute select SQL stetement
rs = statement.executeQuery(selectTableSQL);

} catch (SQLException e) {
} finally {
if (statement != null) {
if (dbConnection != null) {
return rs;

And it is working well. In
ResultSet rs
I'm getting all rows which I need.

How to load them into Vaadin

Answer Source

First of all add container properties

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

Loop through ResultSet

int itemId=1;
   table.addItem(new Object[]{rs.getLong("id"),rs.getString("name")},itemId++);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download