I have a jsp made in adobe dreamweaver which makes queries by date to a table in a database by means of a combo box, but what I need is that in the query that is in another page jsp capture the value that select from the combo box and thus correctly execute my query by date. I would appreciate a lot if you could help me in this. Here I leave the code of the two pages in JSP. This is the one on the first line, the page where the action will be executed.
<%@page language="java" import="java.sql.*" %>
<% Connection g5_clinica=null;
String g5_driver="com.mysql.jdbc.Driver";
String g5_url="jdbc:mysql://localhost:3306/clinica";
String g5_usuario="root";
String g5_clave="";
String g5_mensaje="";
ResultSet rsfecha=null;
try{
Class.forName(g5_driver);
g5_clinica=DriverManager.getConnection(g5_url,g5_usuario,g5_clave);
Statement stprov=g5_clinica.createStatement();
rsfecha=stprov.executeQuery("Select codconsulta,fecatencion from consulta");
}
catch(Exception ex)
{
g5_mensaje=ex.toString();
}
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Modulo de pago</title>
<style type="text/css">
<!--
g5_estilo1 {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 14pt;
font-weight: bold;
}
body,td,th {
color: #00BF60;
}
body {
background-color: #FFF;
}
.G5 {
color: #00BF60;
}
-->
</style>
</head>
<body>
<table width="850" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><h1><span class="G5">Consulta por dia</span></h1></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><form action="g5_tabladeconsultaspordia.jsp" method="post" name="form1" target="g5_tabladeconsultaspordia">
<table width="512" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="325"><h2><span class="G5">Seleccione una fecha</span></h2></td>
<td width="187"><span class="G5">
<label>
<select name="zona" id="zona">
<%
while(rsfecha.next())
{%>
<option value="<% rsfecha.getString(1); %>" > <%=rsfecha.getString(2) %>
</option>
<%} %>
</select>
<input type="submit" name="Submit" value="Consultar">
</label>
</span></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td><span class="G5">
<iframe name="g5_tabladeconsultaspordia" id="g5_tabladeconsultaspordia" width="800" height="200" frameborder="0" scrolling="yes"></iframe>
</span></td>
</tr>
</table>
<h1>
<input type="button" name="Submit2" value="Salir" onclick="window.close()">
</h1>
</body>
</html>
Here is the code of the second page where is the query of the query and where I want the query to take the value or parameter of the combo box and thus be able to correctly query for the day I need.
<%@page language="java" import="java.sql.*" %>
<% Connection conexion=null;
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/clinica";
String usuario="root";
String clave="";
String mensaje="";
String boton;
ResultSet rsclinica=null;
try{
Class.forName(driver);
conexion=DriverManager.getConnection(url,usuario,clave);
Statement stclinica=conexion.createStatement();
rsclinica=stclinica.executeQuery("SELECT codconsulta, codconsultorio , codespecialidad , codigopaciente , fecatencion , "
+"total_apagar, estado, dni_medico, codusuario FROM consulta");
out.println("<TABLE border=1 CellPading=1> <TR>");
out.println("<TH>Codigo de consulta</TH><TH>Codigo de Consultorio</TH><TH>Codigo de especialidad</TH>"
+ "<TH>Codigo de paciente</TH><TH>Fecha de atencion</TH><TH>Total a pagar</TH><TH>Estado</TH>"
+ "<TH>Dni del medico</TH><TH>Codigo de usuario</TH><TH>Fecha de reprogramacion</TH>"
+ "<TH>Reprogramador</TH>");
while(rsclinica.next())
{
out.println("<TR>");
out.println("<TD>"+rsclinica.getString(1)+"</TD>");
out.println("<TD>"+rsclinica.getString(2)+"</TD>");
out.println("<TD>"+rsclinica.getString(3)+"</TD>");
out.println("<TD>"+rsclinica.getString(4)+"</TD>");
out.println("<TD>"+rsclinica.getString(5)+"</TD>");
out.println("<TD>"+rsclinica.getString(6)+"</TD>");
out.println("<TD>"+rsclinica.getString(7)+"</TD>");
out.println("<TD>"+rsclinica.getString(8)+"</TD>");
out.println("<TD>"+rsclinica.getString(9)+"</TD>");
out.println("</TR>");
}
}
catch(Exception ex)
{
mensaje=ex.toString();
}
%>