[英]Pass java variable to sql (netbeans)
I am creating a table, and I want to display the info for the areas the user select. 我正在创建一个表格,并且想要显示用户选择区域的信息。 But when I run the code, it displays only the first check box.
但是,当我运行代码时,它仅显示第一个复选框。
Any help will be greatly appreciated! 任何帮助将不胜感激!
<section>
<p1>Select the areas you want to know about:</p1><br><br>
<form action="Areas_of_knowledge.jsp" method="GET">
<input type="checkbox" name="area_evento" value="Mathematics">Mathematics<br>
<input type="checkbox" name="area_evento" value="Astronomy">Astronomy<br>
<input type="checkbox" name="area_evento" value="Computer Science">Computer Science<br>
<input type="checkbox" name="area_evento" value="Biology">Biology<br>
<input type="checkbox" name="area_evento" value="Physics">Physics<br>
<input type="checkbox" name="area_evento" value="Chemistry">Chemistry<br>
<input type="checkbox" name="area_evento" value="Psychology">Psychology<br>
<input type="checkbox" name="area_evento" value="Human Sciences">Human Sciences<br>
<input type="checkbox" name="area_evento" value="Interdisciplinary">Interdisciplinary<br>
<input type="checkbox" name="area_evento" value="Other">Other<br><br>
<input type="submit" value="Submit" size="50">
</form>
<!-- Ciclo para realizar la consulta -->
<c:if test="${!empty param.area_evento}">
<%
String select[] = request.getParameterValues("area_evento");
if (select != null && select.length != 0) {
for (int i = 0; i < select.length; i++) {
String v = select[i];
%>
<sql:query var="evento" dataSource="jdbc/eventos">
SELECT id_evento, persona_idfk, nom_evento, fecha_evento, num_part_evento, lugar_evento, area_evento FROM evento WHERE area_evento=?
<sql:param value="${param.area_evento}"/>
</sql:query>
<c:if test="${evento.rowCount>0}">
<c:set var="area_evento" value="${evento.rows[0].area_evento}"/>
<!-- Tabla de eventos -->
<table>
<!-- Título de la tabla -->
<caption><h2>Events in ${evento.rows[0].area_evento}</h2></caption>
<!-- Cabezote de la tabla -->
<tr2>
<td>Name</td>
<td>Date</td>
<td>Attendees</td>
<td>Place</td>
<td>Area of Knowledge</td>
</tr2>
<%-- Realiza la consulta para cada valor de los eventos y crea la tabla --%>
<c:forEach var="row" items="${evento.rows}"><tr>
<td><c:out value="${row.nom_evento}"/><br></td>
<td><c:out value="${row.fecha_evento}"/><br></td>
<td><c:out value="${row.num_part_evento}"/><br></td>
<td><c:out value="${row.lugar_evento}"/><br></td>
<td><c:out value="${row.area_evento}"/><br></td>
</tr></c:forEach>
</table>
</c:if>
<c:if test="${evento.rowCount==0}">
<c:set var="nom_evento" value="${evento.rows[0].area_evento}"/>
<caption><h2>There are no events in the area you selected.</h2></caption>
</c:if>
<%
}
}
%>
</c:if>
</section>
<!-- Aquí comienza la equiqueta del pie del sitio -->
<footer>
L&V
</footer>
</body>
Try to change the query to use IN
rather than =
尝试将查询更改为使用
IN
而不是=
<sql:query var="evento" dataSource="jdbc/eventos">
SELECT id_evento, persona_idfk, nom_evento, fecha_evento, num_part_evento, lugar_evento, area_evento FROM evento WHERE area_evento in (?)
<sql:param value="${param.area_evento}"/>
</sql:query>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.