enter image description here I have this code where i try to search data in sql database but it does not show me an error message, instead it runs but the textfields (or input text) disappear. The pic shows the input text should appear between the one named "Matricula" and the one named ""Estatus" This is the part of the code:
<% Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");%>
<%@ page import="java.sql.*"%>
<div id="busqueda">
<table id="bus">
<section id="boton">
<button type="Submit" name="action" value="Entrar" class="btn">Buscar</button>
</section>
<tr>
<td>Matricula:</td>
<td><input id="mat" name="matricula" value="199800" size="20"/></td>
</tr>
<%
String value = request.getParameter("matricula");
Connection conn2 = DriverManager.getConnection("jdbc:sqlserver://192.168.1.124:1433;databasename=Test1;user=sa;password=AlInfinitoYMasAlla@9701");
Statement st2=conn2.createStatement();
ResultSet rs2 = st2.executeQuery("select * from Alumnos where Matricul = '"+value+"'");
if(rs2.next()){
%>
<tr>
<td>Alumno:</td>
<td><input type="text" id="alu" name="alumno" value="<%= rs2.getString("Nombre") %>" size="50"/></td>
</tr>
<%
}
%>
<tr>
<td>Estatus:</td>
<td><input type="text" id="sta" name="status" value="" required size="15"/>Semestre:<input id="sem" name="semestre" value="" required size="10"/></td>
</tr>
So the issue is that wherever i put this: "<% } %>". Anything that is between that and the java code disappears for some reason, i mean that the input text where the results should be printed just do not show at all. I´ve verified a lot on the internet, other people´s code work when it´s exactly the same. I am using netbeans, and glassfish server 4.1.1 Hope someone can help me, thanks in advance.
David
答案 0 :(得分:-1)
Clearly you are not getting anything in rs2. As a result you are not going inside if block. Hence nothing is printing. Please refer What does "if (rs.next())" mean?