<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%!String trans(String chi)
{
String result=null;
byte temp[];
try
{
temp=chi.getBytes("iso-8859-1");
result=new String(temp);
}
catch(Exception e)
{
System.out.println(e.toString());
}
return result;
} %>
<html>
<head>
<title>My JSP 'query.jsp' starting page</title>
</head>
<body>
<center>
以下是从Mysql数据库读取的数据:<hr/>
<table border=1><tr><td>姓名</td><td>手机</td><td>电话</td><td>email</td><td>最后的联系时间</td><td>备注</td></tr>
<%
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/jspdev","root","ADMIN");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from contact;");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+rst.getString("userName")+"</td>");
out.println("<td>"+rst.getInt("mobile")+"</td>");
out.println("<td>"+rst.getString("phone")+"</td>");
out.println("<td>"+trans(rst.getString("mail"))+"</td>");
out.println("<td>"+rst.getDate("lastcontact")+"</td>");
out.println("<td>"+trans(rst.getString("mem"))+"</td>");
out.println("</tr>");
}
rst.close();
stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
%>
</table>
</center>
</body>
</html>
为什么我的数据库jspdev表contact中有多条记录,但执行上面的语句后却只是显示第一条,其他都没有显示?