ResultSet Jasper异常

时间:2013-01-20 23:51:02

标签: java jsp jdbc resultset

我正在尝试使用以下方法投票选出顶级产品。

您可以看到我首先获取所有产品的列表并将结果存储在结果中,并且每个产品我都会获得投票并将其存储在results2中。出于某种原因,尝试results2.getInt("Id")时会出现错误。感谢

public ArrayList<Product> getPollResults() throws ClassNotFoundException, SQLException{
    ArrayList<Product> myProducts = new ArrayList<Product>();
    String query = "SELECT * FROM products";
    connect();        
    PreparedStatement ps = (PreparedStatement) dbConnection.prepareStatement(query);
    ResultSet results = (ResultSet)ps.executeQuery();        
    while(results.next()){
        query= "SELECT COUNT('Votes') AS Votes, pro.Id, pro.ProductDescription, pro.productFileName FROM products pro"
                 +   " JOIN polls poll ON pro.Id = poll.ProductNumber"
                   + " WHERE pro.Id = '"+ results.getInt("Id") +"'";
        ps = (PreparedStatement) dbConnection.prepareStatement(query);
        ResultSet results2 = (ResultSet)ps.executeQuery();   

        myProducts.add(new Product(results2.getInt("Id"), results2.getString("pro.ProductDescription"), results2.getString("pro.productFileName"), results2.getInt("Votes")));
    }        
    disconnect();   
    return myProducts;
}

错误:

org.apache.jasper.JasperException: An exception occurred processing JSP page /polls.jsp at line 24

21:             </div>
22:             <div id="main-container">
23:                 <%db.DBConnection db = new  db.DBConnection(); 
24:                 ArrayList<Product> myProducts =db.getPollResults();
25:                 %>  
26:                 <h1>Polls</h1>
27:                   <form id="Gadgets" action="Gadgets.jsp" method="post">

0 个答案:

没有答案