以下の方法で上位の製品を投票しようとしています。
最初にすべての製品のリストを取得し、結果を結果に保存し、製品ごとに投票を取得して結果 2 に保存していることがわかります。しようとすると、なぜかエラーが表示され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">