I am trying to check if a user has voted or not with this method below. I used the same method as login and login works perfectly. An error is occuring in the ResultSet execute query part. This is to check if the user already voted or not.
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;
}
Stack Trace:
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">