我想检索并打印表abc的所有行,但是这个查询只检索单行。我找不到故障。
String sql= "SELECT * FROM `abc`";
try {
st = con.createStatement();
rs= st.executeQuery(sql);
rs.first();
while(rs.next())
{ String x=rs.getString("x");
String y=rs.getString("y");
String z=rs.getString("z");
String a=rs.getString("a");
out.println(x);%><br><%
out.println(y);%><br><%
out.println(z);%><br><%
out.println(a);%><br><hr>
<%
}
rs.close();%>
答案 0 :(得分:1)
请勿使用rs.first();
。然后试试这段代码:
String sql= "SELECT * FROM `abc`";
try {
st = con.createStatement();
rs= st.executeQuery(sql);
while(rs.next())
{
String x=rs.getString("x");
String y=rs.getString("y");
String z=rs.getString("z");
String a=rs.getString("a");
out.println(x);%><br><%
out.println(y);%><br><%
out.println(z);%><br><%
out.println(a);%><br><hr>
<%
}
rs.close();%>