以下是我的代码,但它一次又一次只选择第一行...... <%
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
String ss=(String)session.getAttribute("ssss");
String sss=(String)session.getAttribute("sss");
PreparedStatement P=c.prepareStatement("Select * from QUESTION where EXAMNAME=?");
P.setString(1,sss);
ResultSet rs=P.executeQuery();
if(rs.next())
{ %>
<form action="newjsp11.jsp" method="post">
Welcome <%=ss%><br>
<input type="text" name="abcd" value="<%= rs.getString(1)%>"><br>
<input type="radio" name="abc" value="<%= rs.getString(2)%>"><%= rs.getString(2)%>
<input type="radio" name="abc" value="<%= rs.getString(3)%>"><%= rs.getString(3)%>
<input type="radio" name="abc" value="<%= rs.getString(4)%>"><%= rs.getString(4)%>
<input type="radio" name="abc" value="<%= rs.getString(5)%>"><%= rs.getString(5)%><br>
<input type="submit" name="Submit"><br><br>
</form>
<% }
%>
这里String ss是学生姓名,sss是考试名称......
答案 0 :(得分:0)
我现在的电脑上没有java,但是这个链接可能对你有所帮助。我猜你的问题是你没有迭代声明的结果。
https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html
所以你的代码看起来应该更少(如果你的代码是如此),就像这样:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
String ss=(String)session.getAttribute("ssss");
String sss=(String)session.getAttribute("sss");
PreparedStatement P=c.prepareStatement("Select * from QUESTION where EXAMNAME=?");
P.setString(1,sss);
ResultSet rs=P.executeQuery();
while (rs.next()) {
%>
<form action="newjsp11.jsp" method="post">
Welcome <%=ss%><br>
<input type="text" name="abcd" value="<%= rs.getString(1)%>"><br>
<input type="radio" name="abc" value="<%= rs.getString(2)%>"><%= rs.getString(2)%>
<input type="radio" name="abc" value="<%= rs.getString(3)%>"><%= rs.getString(3)%>
<input type="radio" name="abc" value="<%= rs.getString(4)%>"><%= rs.getString(4)%>
<input type="radio" name="abc" value="<%= rs.getString(5)%>"><%= rs.getString(5)%><br>
<input type="submit" name="Submit"><br><br>
</form>
<% }
%>