this is my JSP code for using a database to fetch the end time of a meal and compare it to the system time. I've used an if statement to see if time is before the end time, redirect to another page but show an error if time exceeds the end time of a meal.
Here's the catch, The if statement works but not in the way that I just explained.
Any ideas? Thanks in advance...
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%
String meal = request.getParameter("meal");
Connection con = null;
Statement st = null;
ResultSet rs = null;
try{
con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/eoms?autoReconnect=true&useSSL=false","root","eoms");
st=con.createStatement();
String select="SELECT * FROM eoms.schedule;";
rs = st.executeQuery(select);
String mealName = null;
Time dueTime = null;
Time time = null;
int found = 0;
while(rs.next()){
mealName = rs.getString(1);
dueTime = rs.getTime(3);
java.util.Date d = new java.util.Date();
time = new Time(d.getTime());
if(meal.equalsIgnoreCase(mealName) && time.before(dueTime)){
session.setAttribute("mealName", mealName);
con.close();
found = 1;
response.sendRedirect("header.jsp");
}
else
continue;
}
if(found == 0){
session.setAttribute("orderror",meal+mealName+time+dueTime+ "The time for taking the order is over...");
con.close();
response.sendRedirect("placeOrder.jsp");
}
}
catch(Exception e){
out.println(e.getMessage());
}
%>
</body>
</html>