关于分页的一个问题:
在查询的时候我用的是模糊查询,第一页可以正常显示符合条件的共几条,第几条,上一页,下一页,
这时候问题来了,当点下一页的时候,记录就为空了。
但是,我在查询整张表的时候点上一页,下一页是正常显示出来的,如果没有整张表查询,而是通过参数
传递给模糊查询,使符合条件的存到rst中,取出时候点下一页,那么就为空了.
能问问这是怎么回事吗?
我怀疑使指针的问题.
期待能帮我解决的高手,先谢过 ~~~:)
下面是查询和处理页面的代码:
查询页面:
------------main_product_see.jsp--------------------------------------
<%@page language="java" contentType="text/html;charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
font-family: "??ì?";
font-size: 12px;
color: #333333;
}
body {
background-color: #CED7F7;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #FF0000;
}
.style1 {color: #333333}
-->
</style></head><body>
<table width="990" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="990" height="100"><form name="form3" method="post" action="product_see.jsp">
<table width="702" border="1" bordercolor="#1087B9">
<tr>
<td width="648" align="center" valign="middle" bgcolor="#4397c5" class="style1">商品查询</td>
</tr>
<tr>
<td align="left" valign="middle" bgcolor="#BDE2F1">管理快捷方式:<a href="admin_index.jsp" target="_parent">管理首页</a></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#BDE2F1">按
<select name="select4" id="select4">
<option> product_id</option>
<option>product_name</option>
<option>sort_id</option>
<option>product_pubdate</option>
<option>product_sale</option>
</select>
<input name="cha4" type="text" value="">
查询</td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#BDE2F1">
<input type="submit" name="cha4" value="查询"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
---------------------------------product_see.jsp------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%!
public String codeToString(String str)
{//处理中文字符串的函数
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%//接收客户端提交的数据
String sqlString=null;
String cha3=codeToString(request.getParameter("cha4"));
String select3=codeToString(request.getParameter("select4"));
%>
<%
Connection sqlCon;
Statement sqlStmt;
ResultSet sqlRst;
String strCon;
String strSQL;
int intPageSize;
int intRowCount;
int intPageCount;
int intPage;
String strPage;
int i;
intPageSize = 2;
strPage = request.getParameter("page");
if(strPage==null){
intPage = 1;
}
else{
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=shopping","test","test");
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
strSQL="select * from productinf where "+select3+" "+"like'%"+cha3+"%' order by product_id desc";
ResultSet rst=stmt.executeQuery(strSQL);
rst.last();
intRowCount = rst.getRow();
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
if(intPage>intPageCount) intPage = intPageCount;
%>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<title>
test_see
</title>
</head>
<body bgcolor="#ffffff">
<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<th>product_id</th>
<th>product_name</th>
<th>sort_id</th>
<th>product_unitprice</th>
<th>product_stocks</th>
<th>product_publisher</th>
<th>product_pubdate</th>
<th>product_inf</th>
<th>product_sale</th>
</tr>
<%
if(intPageCount>0){
rst.absolute((intPage-1) * intPageSize + 1);
i = 0;
while(i<intPageSize && !rst.isAfterLast()){
%>
<tr>
<td><%=rst.getString(1)%></td>
<td><%=rst.getString(2)%></td>
<td><%=rst.getString(3)%></td>
<td><%=rst.getString(4)%></td>
<td><%=rst.getString(5)%></td>
<td><%=rst.getString(6)%></td>
<td><%=rst.getString(7)%></td>
<td><%=rst.getString(8)%></td>
<td><%=rst.getString(9)%></td></tr>
<%
rst.next();
i++;
}
}
%>
</table>
</table>第<%=intPage%>页 共<%=intPageCount%>页 <%if(intPage<intPageCount){%><a href="product_see.jsp?page=<%=intPage+1%>">下一页</a><%}%> <%if(intPage>1){%><a href="product_see.jsp?page=<%=intPage-1%>">上一页</a><%}%>
</body>
</html>
<%
rst.close();
stmt.close();
conn.close();
%>
在查询的时候我用的是模糊查询,第一页可以正常显示符合条件的共几条,第几条,上一页,下一页,
这时候问题来了,当点下一页的时候,记录就为空了。
但是,我在查询整张表的时候点上一页,下一页是正常显示出来的,如果没有整张表查询,而是通过参数
传递给模糊查询,使符合条件的存到rst中,取出时候点下一页,那么就为空了.
能问问这是怎么回事吗?
我怀疑使指针的问题.
期待能帮我解决的高手,先谢过 ~~~:)
下面是查询和处理页面的代码:
查询页面:
------------main_product_see.jsp--------------------------------------
<%@page language="java" contentType="text/html;charset=gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
body,td,th {
font-family: "??ì?";
font-size: 12px;
color: #333333;
}
body {
background-color: #CED7F7;
}
a:link {
color: #000000;
}
a:visited {
color: #000000;
}
a:hover {
color: #FF0000;
}
.style1 {color: #333333}
-->
</style></head><body>
<table width="990" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="990" height="100"><form name="form3" method="post" action="product_see.jsp">
<table width="702" border="1" bordercolor="#1087B9">
<tr>
<td width="648" align="center" valign="middle" bgcolor="#4397c5" class="style1">商品查询</td>
</tr>
<tr>
<td align="left" valign="middle" bgcolor="#BDE2F1">管理快捷方式:<a href="admin_index.jsp" target="_parent">管理首页</a></td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#BDE2F1">按
<select name="select4" id="select4">
<option> product_id</option>
<option>product_name</option>
<option>sort_id</option>
<option>product_pubdate</option>
<option>product_sale</option>
</select>
<input name="cha4" type="text" value="">
查询</td>
</tr>
<tr>
<td align="center" valign="middle" bgcolor="#BDE2F1">
<input type="submit" name="cha4" value="查询"></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>
---------------------------------product_see.jsp------------------------------
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%!
public String codeToString(String str)
{//处理中文字符串的函数
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%//接收客户端提交的数据
String sqlString=null;
String cha3=codeToString(request.getParameter("cha4"));
String select3=codeToString(request.getParameter("select4"));
%>
<%
Connection sqlCon;
Statement sqlStmt;
ResultSet sqlRst;
String strCon;
String strSQL;
int intPageSize;
int intRowCount;
int intPageCount;
int intPage;
String strPage;
int i;
intPageSize = 2;
strPage = request.getParameter("page");
if(strPage==null){
intPage = 1;
}
else{
intPage = java.lang.Integer.parseInt(strPage);
if(intPage<1) intPage = 1;
}
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=shopping","test","test");
Statement stmt = conn.createStatement(java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE,java.sql.ResultSet.CONCUR_READ_ONLY);
strSQL="select * from productinf where "+select3+" "+"like'%"+cha3+"%' order by product_id desc";
ResultSet rst=stmt.executeQuery(strSQL);
rst.last();
intRowCount = rst.getRow();
intPageCount = (intRowCount+intPageSize-1) / intPageSize;
if(intPage>intPageCount) intPage = intPageCount;
%>
<html>
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">
<title>
test_see
</title>
</head>
<body bgcolor="#ffffff">
<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<th>product_id</th>
<th>product_name</th>
<th>sort_id</th>
<th>product_unitprice</th>
<th>product_stocks</th>
<th>product_publisher</th>
<th>product_pubdate</th>
<th>product_inf</th>
<th>product_sale</th>
</tr>
<%
if(intPageCount>0){
rst.absolute((intPage-1) * intPageSize + 1);
i = 0;
while(i<intPageSize && !rst.isAfterLast()){
%>
<tr>
<td><%=rst.getString(1)%></td>
<td><%=rst.getString(2)%></td>
<td><%=rst.getString(3)%></td>
<td><%=rst.getString(4)%></td>
<td><%=rst.getString(5)%></td>
<td><%=rst.getString(6)%></td>
<td><%=rst.getString(7)%></td>
<td><%=rst.getString(8)%></td>
<td><%=rst.getString(9)%></td></tr>
<%
rst.next();
i++;
}
}
%>
</table>
</table>第<%=intPage%>页 共<%=intPageCount%>页 <%if(intPage<intPageCount){%><a href="product_see.jsp?page=<%=intPage+1%>">下一页</a><%}%> <%if(intPage>1){%><a href="product_see.jsp?page=<%=intPage-1%>">上一页</a><%}%>
</body>
</html>
<%
rst.close();
stmt.close();
conn.close();
%>
解决方案 »
- Maximum column length of 100,000 exceeded in column 29 in record 7,603. Set the
- tomcat下,无法访问ireport生成的报表文件,提示http 404,如何解决?
- (在线求解)怎么在java代码里(不是jsp)调用网页打印
- java程序里再调用java的程序怎么做?
- javascript中的中文转换问题
- JSP简单留言本(SQLserver2000版)下载到本机,怎么设定?
- 如何用eclipse新建wml文件
- 请问:如何给request或response手动增加一个header?
- jsp如何嵌套入自己用JAVA开发的播放器
- jsp 如何实现 IE文件菜单中‘另存为’的功能。简单的说就是在网页中加个按钮,点击之后可以把本页的页面另存为txt/html文件。在线等待,
- 在jsp页面我要调取数据库中body的一部分内容
- 怎么将客户端的ACCES库中的数据导入到服务器上的ORACLE表中?
比如
<a href="MeetingInfoQuery.jsp?page=<%=intPage-1%>&a=<%=queryString1%>&b=<%=queryString2%>&flag=<%=flag%>">上一页></a>>
可能是我传的有误吧~~
能针对,我的这些代码具体点吗?
期待中:)
每次进来的时候都会重新从数据库检索,你的链接href="product_see.jsp?page=<%=intPage+1%>"> 链接的目标jsp好象是main_product_see.jsp吧,如果是的话上面的连接可不就写错了
,你的程序我还真看不出有什么其它的错误了,可能是我太菜了吧!!!
你可以使用TOP N * 来取数据,然后根据页面POST的CURPAGE_NO,来处理得到每次查询的开始记录SEQ和结束记录SEQ,然后在循环取数据的时候,根据一个ICOUNT来取出需要的数据..