when I click search button, I can't get an accurate output. I want the query get the output based on selected comparison operator but it not working...below are my trial coding in JSP
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>contion three testing</title> </head> <body> <form name="form1" method="post" action=""> <table width="520" border="2"> <tr bgcolor="#99CCCC"> <th width="190" scope="row">DATA ID</th> <td width="222"><input type="text" name="textfield"></td> </tr> <tr bgcolor="#99CCCC"> <th scope="row">VALID START DATE</th><td> <select name="select1" size="1"> <option value="-1">--Select Operator--</option> <option value="=">=</option> <option value=">">></option> <option value=">=">>=</option> </select> <input type="text" name="text1" </td> </tr> <tr bgcolor="#99CCCC"> </table> <p> <input type="submit" name="Submit" value="Search"> <input type="reset" name="Reset" value="Reset"> <% String id =request.getParameter("textfield"); String list1=request.getParameter("select1"); String start = request.getParameter("text1"); Connection con = null; Statement stmt = null; String connectionURL = "jdbc:mysql://localhost:3306/test"; Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection(connectionURL, "root", "farham"); stmt = con.createStatement(); String qry ="select data_id,date_format(transaction_date,'%d/%m/%Y')as transaction_date,operator1,date_format(valid_from,'%d/%m/%Y')as valid_from," + "operator2,date_format(valid_until,'%d/%m/%Y')as valid_until from time_element where data_id='"+id+"'"; if(list1!=null && (list1.equals("="))){ qry+="and date_format(valid_from,'%d/%m/%Y')='"+start+"'"; } else if(list1!=null && (list1.equals(">"))){ qry+="and date_format(valid_from,'%d/%m/%Y')>'"+start+"'"; } else{ qry+="and date_format(valid_from,'%d/%m/%Y')>='"+start+"'"; } ResultSet rst = stmt.executeQuery(qry); %> </p> <p><table width="785" border="3" bordercolor="#99CCCC"> <td width="32"><div align="center"><strong>Data Id</strong></div></td> <td width="124"><div align="center"><strong>Transaction Date </strong></div></td> <td width="110"><div align="center"><strong>Operator1 </strong></div></td> <td width="124"><div align="center"><strong>Valid Start Date </strong></div></td> <td width="110"><div align="center"><strong>Operator2 </strong></div></td> <td width="124"><div align="center"><strong>Valid End Date </strong></div></td> <% while (rst.next()) { %> <tr> <td><div align="center"><%=rst.getString("data_id")%></div></td> <td><div align="center"><%=rst.getString("transaction_date")%></div></td> <td><div align="center"><%=rst.getString("operator1")%></div></td> <td><div align="center"><%=rst.getString("valid_from")%></div></td> <td><div align="center"><%=rst.getString("operator2")%></div></td> <td><div align="center"><%=rst.getString("valid_until")%></div></td> </tr> <%} %> </table> </form> </body> </html>