从 mysql 读数据时只能读第一条
程序代码:
显示账单 0"); out.print(""); out.print(""); out.print("金额"); out.print("方式"); out.print("类别"); out.print(""); while(rs.next()){ out.print(""); out.print(""+rs.getString(1)+""); out.print(""+rs.getString(2)+""); out.print(""+rs.getString(3)+""); out.print(""+rs.getString(4)+""); out.print(""+rs.getString(5)+""); out.print(""); } out.print(""); }catch(SQLException e){ e.printStackTrace(); }finally{ try{ if(rs!=null){ rs.close(); } if(st!=null){ st.close(); } if(con!=null){ con.close(); } }catch(SQLException e){ e.printStackTrace(); } } %> <%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%> <%@page import="java.sql.*" %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www. http-equiv="Content-Type" content="text/html; charset=GBK"> <title>显示账单</title> </head> <body> <% Connection con=null; Statement st=null; ResultSet rs=null; try{ Class.forName("com.mysql.jdbc.Driver"); }catch(ClassNotFoundException e ){ e.printStackTrace(); } try{ con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydatabase","root","root"); st=con.createStatement(); rs=st.executeQuery("select * from zhangdan where jine>0"); out.print("<table border=1>"); out.print("<tr>"); out.print("<th>金额</th>"); out.print("<th>方式</th>"); out.print("<th>类别</th>"); out.print("</tr>"); while(rs.next()){ out.print("<tr>"); out.print("<td>"+rs.getString(1)+"</td>"); out.print("<td>"+rs.getString(2)+"</td>"); out.print("<td>"+rs.getString(3)+"</td>"); out.print("<td>"+rs.getString(4)+"</td>"); out.print("<td>"+rs.getString(5)+"</td>"); out.print("</tr>"); } out.print("</table>"); }catch(SQLException e){ e.printStackTrace(); }finally{ try{ if(rs!=null){ rs.close(); } if(st!=null){ st.close(); } if(con!=null){ con.close(); } }catch(SQLException e){ e.printStackTrace(); } } %> </body> </html>不是说从数据库中得到的结果先放在rs中。然后再逐条读取么。可是我都给出5条了。为什么只能读出一条来。
卡这好几天了。求救啊