【问题标题】:Vaadin access content of sql containerVaadin访问sql容器的内容
【发布时间】:2016-07-17 11:55:14
【问题描述】:

已编辑!

我使用 Vaadin、SQLContainer 和 Freeformquery 从 mysql 数据库中检索数据。现在我想在一个字符串中获取所有描述(稍后每个字符串将打印/添加到文本文件中)。

....
String text ="";
FreeformQuery subcatExtractionQuery = new FreeformQuery("select Description from customers", connectionPool);
SQLConateiner s = new SQLContainer(subcatExtractionQuery);

Collection<?> c = s.getContainerPropertyIds();
    for(Object o : c){
        Property<?> p = s.getContainerProperty(o, "Description");
        text+=(String)p.getValue();
    }
    System.out.println(text);

我收到错误:java.lang.NullPointerException 问题行是 text+=... 如果我删除它,则不会出现错误。但是查询返回数据!

这些描述是字符串。我需要在单个标记列表中包含每个字符串的所有单词(我已经有一种方法来创建文件的标记列表。) (不要问这是否有意义,这只是一个例子)。

如何访问我的 sql 容器的字符串?到目前为止,我只使用了表的容器 als 数据源,没有访问单个项目/字符串。 我需要一个 for 循环来获取每个字符串...这是如何工作的?

【问题讨论】:

  • 有点不清楚你想要实现什么,因为这听起来更适合基本的 JDBC/ORM 查询,没有任何其他 Vaadin 交互,除了可能是一个按钮点击......你在尝试吗将您在表格/网格/等中显示的数据保存到文件或..?请提供更多详细信息。
  • 您可以从容器中检索所有 ItemId(标识行),然后使用 getItemProperty(..) 检索字段的值
  • 我这样做了:FreeformQuery subcatExtractionQuery = new FreeformQuery("select Message from "+sqlPart, connectionPool); SQLContainer s = new SQLContainer(subcatExtractionQuery);但这不起作用 Collection t = s.getContainerPropertyIds(); for(对象 o : t){ o.getItemProperty(); }

标签: java parsing vaadin


【解决方案1】:

它的 getItemIds 被设置为 getContainerPropertyIds。所以这句话

....
String text ="";
FreeformQuery subcatExtractionQuery = new FreeformQuery("select Description from customers", connectionPool);
SQLConateiner s = new SQLContainer(subcatExtractionQuery);

Collection<?> c = s.getItemIds();
for(Object o : c){
    Property<?> p = s.getContainerProperty(o, "Description");
    text+=(String)p.getValue();
}
System.out.println(text);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-24
    • 2018-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多