在网格vaadin中显示SQL查询数据
我想在网格vaadin中显示我的SQL查询的结果,
我可以从toto表中获取数据,
但是我无法在网格中显示它们
如何做?
public class MainView extends VerticalLayout {
private CustomerService service = CustomerService.getInstance();
private Grid<Customer> grid = new Grid<>(Customer.class);
public MainView() {
/*Button button = new Button("Click me",
event -> Notification.show("Clicked!"));
add(button);*/
//BDD
try{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@xxxx:1521:chan","xxx","xxx");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from toto");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
//step5 close the connection object
con.close();
}catch(Exception e){ System.out.println(e);}
//GRID
grid.setColumns("firstName", "lastName", "status");
add(grid);
setSizeFull();
updateList();
}
public void updateList()
{
grid.setItems(service.findAll());
}
}
我通过添加网格修改了代码,现在我想了解如何在网格中显示查询结果
I would like to display the result of my SQL query in a grid vaadin
I can get the data from my toto table
But I can't display them in a grid
How to do it?
public class MainView extends VerticalLayout {
private CustomerService service = CustomerService.getInstance();
private Grid<Customer> grid = new Grid<>(Customer.class);
public MainView() {
/*Button button = new Button("Click me",
event -> Notification.show("Clicked!"));
add(button);*/
//BDD
try{
//step1 load the driver class
Class.forName("oracle.jdbc.driver.OracleDriver");
//step2 create the connection object
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@xxxx:1521:chan","xxx","xxx");
//step3 create the statement object
Statement stmt=con.createStatement();
//step4 execute query
ResultSet rs=stmt.executeQuery("select * from toto");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3));
//step5 close the connection object
con.close();
}catch(Exception e){ System.out.println(e);}
//GRID
grid.setColumns("firstName", "lastName", "status");
add(grid);
setSizeFull();
updateList();
}
public void updateList()
{
grid.setItems(service.findAll());
}
}
I modified my code by adding a grid, now I would like to understand how I can display the results of my query in my grid
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已经用
网格&lt; customer&gt;
定义了类型客户的网格。这意味着可以通过提供客户列表来设置网格。使用您的代码示例:You have defined a Grid of the type Customer with
Grid<Customer>
. This means the Grid can be set up by providing a List of Customers. Using your code example: