JSP高手请进,JSP中的数据查询问题!

来源:百度知道 编辑:UC知道 时间:2024/09/18 17:03:19
我的这个程序在查询时总是从第二条开始,不查询第一条,是怎么回事啊!
<%@ page language="java"contentType="text/html;charset=gb2312"%>
<%@ include file="../public/adcheck.jsp" %>
<%@ include file="../public/common.jsp"%>
<%@ include file="../public/connectdb.jsp"%>

<%
String wbname2=request.getParameter("wbname1");
wbname2=new String(wbname2.getBytes("ISO-8859-1"));
try
{
sql="select * from smessage where wbname='"+wbname2+"'";
rs=stmt.executeQuery(sql);
if(!rs.next())
{
String error="error2";
response.sendRedirect("wbmessage.jsp?error="+error);
}
else
{

%>

<html>
<head>
<title>鑫贸网络科技有限公司</title>
<style type="text/css">
<!--
.style1 {font-size:red 24px}
-

if(!rs.next())
这句判断的时候,指针已经下移一条,到第一条记录了,后面循环的时候
while(rs.next())
你又下移了一条,就到第二条了

观点同一楼,想获得查询条数可以使用sql句 select count(*) from smessage where wbname="wbname2"; 就可以解决,不过我想rs应该有自己的方法,类似rs.getSize(),或者rs.count(),什么的,呵呵,我没环境只是猜的,希望能帮到你!