Java add all table data into list

前端 未结 1 417
执笔经年
执笔经年 2021-01-24 09:55
+--------+-------+-----+
|  Name  |number |qty  |
+--------+-------+-----+
|   ab   |   5   |  7  |
+--------+-------+-----+ 
|   cd   |   1   |  6  |
+--------+-------+         


        
1条回答
  •  余生分开走
    2021-01-24 09:59

    Make your search() method return a List instead of a single Product.

    public List search(){
        List products = new ArrayList();
        ResultSet rs = DAO.fetch("SELECT * FROM Products");
        while (rs.next()) {
            Product product = new Product();
            product.setNumber(rs.getString("ProductNumber"));
            product.setName(rs.getString("ProductName"));
            product.setQty(rs.getString("ProductQty"));
            products.add(product);
        }
        return products;
    }
    

    Then, in your JSP file, iterate over the returned list:

    
        
    
    

    0 讨论(0)
提交回复
热议问题