我有显示一个图表,其填充有数据从SQL表的应用程序。我正在寻找让用户“编辑”表的可能性,以便他可以更改图表。今天我发现了Vaadin“SQLContainer”插件,这正是我所需要的。我能够连接到数据库并获取我需要的表并将其连接到Vaadin表,以便在Vaadin中查看数据库表。我已经阅读了很多次有关SQLContainer(更新的AdressBook教程)的Vaadin教程,但我仍然不知道如何通过SQLContainer提交某些内容给DB。这是我到目前为止:Vaadin:提交新的项目数据库(SQLContainer)
public void displayTable(){
try {
connectionPool = new SimpleJDBCConnectionPool(
"org.postgresql.Driver",
"jdbc:postgresql://localhost:5432/database", "username", "password", 2, 5);
FreeformQuery query = new FreeformQuery("select * FROM table", connectionPool);
container = new SQLContainer(query);
container.addListener(new QueryDelegate.RowIdChangeListener() {
public void rowIdChange(RowIdChangeEvent event) {
System.err.println("Old ID: " + event.getOldRowId());
System.err.println("New ID: " + event.getNewRowId());
}
});
} catch (SQLException e) {
e.printStackTrace();
}
table= new Table("Table",container);
table.setSelectable(true);
table.addListener(this);
window.addComponent(table);
}
}
我正在与Vaadin版本6.6.6和我使用PostgrSQL。
顺便说一句,你可能会在新的Vaadin [网]与7版本当前版本捆绑(https://vaadin.com/grid)部件有趣它包括一个内置的编辑窗格。参见[Vaadin之书](https://vaadin.com/book/vaadin7/-/page/components.grid.html)。 –