您好Stackoverflow成员,
我有一个带有TableQuery的SQLContainer。现在,我想在一列中获取所有值。我怎么才能得到它?或者我需要使用FreefromQuery吗?
这是我的SQLContainer代码
public SQLContainer getMyContainer() {
//FreeformQuery query = null;
SQLContainer container = null;
try {
connectionPool = new SimpleJDBCConnectionPool(
"com.mysql.jdbc.Driver",
"jdbc:mysql://localhost:3306/vaadin", "root", "root",
2, 5);
TableQuery query = new TableQuery("components", connectionPool);
/*query = new FreeformQuery(
"SELECT rowNum, colNum, caption, cType FROM items where screenId='"
+ screenName+"'", connectionPool);
query.setDelegate(new DemoFreeformQueryDelegate());*/
container = new SQLContainer(query);
} catch (Exception e) {
}
return container;
}
答案 0 :(得分:1)
这取决于你想做什么。
使用SQLContainer,您可以这样做:
// Returns a list with all ID's (Beware of large resultsets)
Collection<?> itemIDS= conatiner.getItemIds();
for (Object itemID : itemIDS)
{
Property property= container.getContainerProperty(itemID, "COLUMN");
Object data= property.getValue();
}
getItemIds()必须从DB中获取所有行(至少是主键), 所以这会导致大型结果集/表格出现问题。
https://vaadin.com/api/com/vaadin/data/util/sqlcontainer/SQLContainer.html#getItemIds%28%29