我正在尝试使用以下方法检查用户是否已投票。我使用了与登录相同的方法,登录效果很好。ResultSet 执行查询部分发生错误。这是为了检查用户是否已经投票。
public boolean checkVote(int userId) throws ClassNotFoundException, SQLException{
String query = "SELECT * FROM polls WHERE User='"+ userId +"''";
connect();
PreparedStatement ps = (PreparedStatement) dbConnection.prepareStatement(query);
ResultSet results = (ResultSet)ps.executeQuery();
while(results.next())
{
return true;
}
disconnect();
return false;
}
堆栈跟踪:
org.apache.jasper.JasperException: An exception occurred processing JSP page / Gadgets.jsp at line 40
37: <%db.DBConnection db = new db.DBConnection();
38: ArrayList<Product> myProducts =db.getAllProducts();
39: User u = db.getUser(session.getAttribute("Username").toString());
40: boolean checkVote = db.checkVote(u.getId());
41: if(checkVote == true)
42: { %>
43: <form id="Gadgets" action="Gadgets.jsp" method="post">