我用StringBuffer作了多条件查询后以前的分页就不管用了,请问这样应该怎么做分页啊??
我用的数据库是oracle。MYSQL那个方法用不了,虽然实现了多条件查询后以前的分页但是还是觉得我用的方法笨笨的,先凑合着用吧,呵呵谢谢大家的热心帮助。
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="com.cdx.share.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%DBAccess db=new DBAccess("java:comp/env/jdbc/SLLY");%>
<%request.setCharacterEncoding("GB2312");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
<LINK href="../css/cssDefault.css" type=text/css rel=stylesheet>
</head>
<body><table class=table1 cellspacing="1">
<%
String WATERSYSTEM=request.getParameter("WATERSYSTEM");
String D_TYPE=request.getParameter("D_TYPE");
String EA_TIME=request.getParameter("EA_TIME");
String RIVERNAME=request.getParameter("RIVERNAME");
String C_LOCUS=request.getParameter("C_LOCUS");
String D_DATE=request.getParameter("D_DATE");
StringBuffer sql=new StringBuffer("select * from T_DISSENSION t where 1=1 ");
if (WATERSYSTEM!=null&&!"".equals(WATERSYSTEM))
sql.append(" and t.WATERSYSTEM='"+WATERSYSTEM+"'" );
if (D_TYPE!=null&&!"".equals(D_TYPE))
sql.append(" and t.D_TYPE='"+D_TYPE+"'" );
if (EA_TIME!=null&&!"".equals(EA_TIME))
sql.append(" and t.EA_TIME='"+EA_TIME+"'" );
if (RIVERNAME!=null&&!"".equals(RIVERNAME))
sql.append(" and t.RIVERNAME='"+RIVERNAME+"'");
if (C_LOCUS!=null&&!"".equals(C_LOCUS))
sql.append(" and t.C_LOCUS='"+C_LOCUS+"'" );
if (D_DATE!=null&&!"".equals(D_DATE))
sql.append(" and t.D_DATE='"+D_DATE+"'" );
CDXResultSet rs=db.execQuery(sql.toString());
%>
<form name="frm1" method="post" action="DISSENSION.jsp">
<tr>
<td class=td3>选择河系</td>
<td class=td2>
<select name="WATERSYSTEM" class=select2>
<option value="" selected>-河系名称-</option>
<option value="黑龙江水系">黑龙江水系</option>
<option value="乌苏里江水系">乌苏里江水系</option>
<option value="绥芬河水系">绥芬河水系</option>
<option value="图们江水系">图们江水系</option>
<option value="额尔古纳河水系">额尔古纳河水系</option>
<option value="鸭绿江水系">鸭绿江水系</option>
<option value="其它(界湖)">其它(界湖)</option>
</select></td>
<td class=td3>选择类别</td>
<td class=td2>
<SELECT NAME="D_TYPE" class=select2>
<option value="" selected>-类型名称-</option>
<option value="水事纠纷">水事纠纷</option>
<option value="非水事纠纷">非水事纠纷</option>
</SELECT></td>
<td class=td3>审批时间</td>
<td class=td2><input class=text3 type="text" name="EA_TIME" value=""></td>
</tr>
<tr>
<td class=td3>河流名称</td>
<td class=td2><input class=text3 type="text" name="RIVERNAME" value=""></td>
<td class=td3>所在县市</td>
<td class=td2><input class=text3 type="text" name="C_LOCUS" value=""></td>
<td class=td3>时间</td>
<td class=td2><input class=text3 type="text" name="D_DATE" value=""></td>
</tr>
<tr class=trbottom>
<td colspan="6">
<input name=Submit type=image "img src="../images/button/btnQuery.gif" border="0">
<a href="DISSENSION_register.jsp"><img src="../images/button/btnAdd.gif" border="0"></a>
<input name=Back type=image "img src="../images/button/btnBack.gif" onClick="history.back(-1)" border="0"></td>
</tr>
</table>
</form>
<table class=table1 cellspacing="1">
<tr class=trhead>
<td width="16%">河流名称</td>
<td width="18%">所在县市</td>
<td width="18%">时间</td>
<td width="18%">类型</td>
<td width="15%">照会内容</td>
<td width="15%">备注</td>
</tr>
<%
while(rs.next()){
%>
<tr class=tr1>
<td><%=rs.getString("RIVERNAME")%></td>
<td><%=rs.getString("C_LOCUS")%></td>
<td><%=rs.getString("D_DATE")%></td>
<td><%=rs.getString("D_TYPE")%></td>
<td><%=rs.getString("NOTE")%></td>
<td><%=rs.getString("REMARK")%></td>
</tr>
<%}}%>
<tr class=trbottom>
<td colspan="6" >
</td>
</tr>
</table>
</body>
</html>
[此贴子已经被作者于2006-9-25 9:43:37编辑过]
----------------解决方案--------------------------------------------------------
我也正为这事头痛呢
----------------解决方案--------------------------------------------------------
啊呀。。你找到解决办法了的话麻烦你也告诉我
----------------解决方案--------------------------------------------------------
以前分页的代码呢
----------------解决方案--------------------------------------------------------
什么叫以前的分页不管用了??简单查询和带参数查询都是查询都是返回结果集 一样一样一样地呀
----------------解决方案--------------------------------------------------------
以前用这个分页的,但是用了StringBuffer后就不知道该怎么用了
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="com.cdx.share.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%DBAccess db=new DBAccess("java:comp/env/jdbc/SLLY");%>
<%request.setCharacterEncoding("GB2312");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>国际河流名称总表</title>
<LINK href="css/cssDefault.css" type=text/css rel=stylesheet>
</head>
<body><div><tr> </tr>
<table class=table1 cellspacing="1">
<tr height="20">
<td background="images/table/bg_line4.jpg" class=td4 colspan=8>
<IMG src="images/table/ball.gif">国 际 河 流 名 称 总 表<IMG src="images/table/ball.gif">
</td></tr>
<form method="post" action="T_R_N_L.jsp">
<tr>
<td width="20%" class=td3>选择河系</td>
<td colspan="2" width="20%" class=td2>
<select name="WATERSYSTEM" class=select2>
<option value="" selected>-河系名称-</option>
<option value="黑龙江水系">黑龙江水系</option>
<option value="乌苏里江水系">乌苏里江水系</option>
<option value="绥芬河水系">绥芬河水系</option>
<option value="图们江水系">图们江水系</option>
<option value="额尔古纳河水系">额尔古纳河水系</option>
<option value="鸭绿江水系">鸭绿江水系</option>
<option value="其它(界湖)">其它(界湖)</option>
</select></td>
<td width="20%" class=td3>选择类别</td>
<td colspan="2" width="20%" class=td2>
<SELECT NAME="WATERSYSTEMTYPE" class=select2>
<option value="" selected>-河系类别-</option>
<option value="干流">干流</option>
<option value="一级支流">一级支流</option>
<option value="二级支流">二级支流</option>
<option value="其它">其它</option>
</SELECT></td>
<td colspan="2" width="20%" class=td3>
<input type="Submit" value="检索" name="js" class=button1></td>
</tr>
</form>
<form name="fm" method="post" action="">
<tr class=trhead>
<td>河流名称</td>
<td>河流编码</td>
<td>所属河系</td>
<td>上级河流名称</td>
<td>上级河流编码</td>
<td>所属河系类型</td>
<td>两岸国别</td>
<td>备注</td>
</tr>
<%
//添加翻页
int i=0;
MultiPage mp = MultiPage.getInstance(request);
ArrayList al = new ArrayList();//数组
ArrayList altemp = new ArrayList();
String WATERSYSTEM = request.getParameter("WATERSYSTEM");
String WATERSYSTEMTYPE = request.getParameter("WATERSYSTEMTYPE");
String sql="";
if(!WATERSYSTEM.equals("")&&!WATERSYSTEMTYPE.equals(""))
{
al=db.executeQuery("select * from T_RIVERNAME where WATERSYSTEM='"+WATERSYSTEM+"' and WATERSYSTEMTYPE='"+WATERSYSTEMTYPE+"'");
}
else if(WATERSYSTEM.equals("")&&WATERSYSTEMTYPE.equals(""))
{
al=db.executeQuery("select * from T_RIVERNAME");
}
else if(!WATERSYSTEM.equals("")&&WATERSYSTEMTYPE.equals(""))
{
al=db.executeQuery("select * from T_RIVERNAME where WATERSYSTEM='"+WATERSYSTEM+"'");
}
else if(WATERSYSTEM.equals("")&&!WATERSYSTEMTYPE.equals(""))
{
al=db.executeQuery("select * from T_RIVERNAME where WATERSYSTEMTYPE='"+WATERSYSTEMTYPE+"'");
}
mp.setPageData("cny",al) ;
al = (ArrayList)mp.getPageData("cny") ;
mp.setTotalSize(al.size());
for (i=mp.getStartRowNo();i<mp.getEndRowNo();i++){
altemp = (ArrayList)al.get(i) ;
%>
<tr class='<%=(i%2==0)?"tr1":"tr2"%>'><!--三目运算符-->
<td><%=altemp.get(1)%></td>
<td><%=altemp.get(0)%></td>
<td><%=altemp.get(2)%></td>
<td><%=altemp.get(3)%></td>
<td><%=altemp.get(4)%></td>
<td><%=altemp.get(5)%></td>
<td><%=altemp.get(6)%></td>
<td><%=altemp.get(7)%></td>
</tr>
<%}%>
<tr class=trbottom>
<td colspan="8" >
<%=mp.getNavigation("T_R_N_L.jsp")%>
</td>
</tr>
<input type="hidden" name="WATERSYSTEM" value="<%=altemp.get(2)%>">
<input type="hidden" name="WATERSYSTEMTYPE" value="<%=altemp.get(5)%>">
</form>
</table>
</body>
</html>
----------------解决方案--------------------------------------------------------
在线等,谢谢高手指点迷津啊
----------------解决方案--------------------------------------------------------
这中间有个Bug sql.toString() 只有其中一部分 sql.subString()可以全部显示
CDXResultSet rs=db.execQuery(sql.substring(0));
----------------解决方案--------------------------------------------------------
哇,好高兴,终于有人教我做了,我这就去试试,嘿嘿,谢谢!!!
----------------解决方案--------------------------------------------------------
哎呀。我试过了,用sub替换to就直接报错。。。。
现在不报错了,但是分页分了用不了fm.iPageSize说这个缺少对象
<%@ page contentType="text/html; charset=GBK"%>
<%@ page import="com.cdx.share.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%DBAccess db=new DBAccess("java:comp/env/jdbc/SLLY");%>
<%request.setCharacterEncoding("GB2312");%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>水事纠纷</title>
<LINK href="../css/cssDefault.css" type=text/css rel=stylesheet>
</head>
<body><div><tr> </tr>
<table class=table1 cellspacing="1">
<tr height="20">
<td background="../images/table/bg_line4.jpg" class=td4 colspan=6>
<img src="../images/table/ball.gif">水 事 纠 纷<img src="../images/table/ball.gif"></td></tr>
<form name="fm" method="post" action="DISSENSION.jsp">
<tr>
<td class=td3>选择河系</td>
<td class=td2>
<select name="WATERSYSTEM" class=select2>
<option value="" selected>-河系名称-</option>
<option value="黑龙江水系">黑龙江水系</option>
<option value="乌苏里江水系">乌苏里江水系</option>
<option value="绥芬河水系">绥芬河水系</option>
<option value="图们江水系">图们江水系</option>
<option value="额尔古纳河水系">额尔古纳河水系</option>
<option value="鸭绿江水系">鸭绿江水系</option>
<option value="其它(界湖)">其它(界湖)</option>
</select></td>
<td class=td3>选择类别</td>
<td class=td2>
<SELECT NAME="D_TYPE" class=select2>
<option value="" selected>-类型名称-</option>
<option value="水事纠纷">水事纠纷</option>
<option value="非水事纠纷">非水事纠纷</option>
</SELECT></td>
<td class=td3>审批时间</td>
<td class=td2><input class=text3 type="text" name="EA_TIME" value=""></td>
</tr>
<tr>
<td class=td3>河流名称</td>
<td class=td2><input class=text3 type="text" name="RIVERNAME" value=""></td>
<td class=td3>所在县市</td>
<td class=td2><input class=text3 type="text" name="C_LOCUS" value=""></td>
<td class=td3>时间</td>
<td class=td2><input class=text3 type="text" name="D_DATE" value=""></td>
</tr>
<tr class=trbottom>
<td colspan="6">
<input name=Submit type=image "img src="../images/button/btnQuery.gif" border="0">
<a href="DISSENSION_register.jsp"><img src="../images/button/btnAdd.gif" border="0"></a>
<input name=Back type=image "img src="../images/button/btnBack.gif" onClick="history.back(-1)" border="0"></td>
</tr>
</table>
</form>
<table class=table1 cellspacing="1">
<tr height="20">
<td background="images/table/bg_line4.jpg" class=td4 colspan=6>水事纠纷信息表</td>
</tr>
<tr class=trhead>
<td width="16%">河流名称</td>
<td width="18%">所在县市</td>
<td width="18%">时间</td>
<td width="18%">类型</td>
<td width="15%">照会内容</td>
<td width="15%">备注</td>
</tr>
<%
//添加翻页
int i=0;
MultiPage mp = MultiPage.getInstance(request);
ArrayList al = new ArrayList();//数组
ArrayList altemp = new ArrayList();
String WATERSYSTEM=request.getParameter("WATERSYSTEM");
String D_TYPE=request.getParameter("D_TYPE");
String EA_TIME=request.getParameter("EA_TIME");
String RIVERNAME=request.getParameter("RIVERNAME");
String C_LOCUS=request.getParameter("C_LOCUS");
String D_DATE=request.getParameter("D_DATE");
StringBuffer sql=new StringBuffer("select * from T_DISSENSION t where 1=1 ");
if (WATERSYSTEM!=null&&!"".equals(WATERSYSTEM))
sql.append(" and t.WATERSYSTEM='"+WATERSYSTEM+"'");
if (D_TYPE!=null&&!"".equals(D_TYPE))
sql.append(" and t.D_TYPE='"+D_TYPE+"'");
if (EA_TIME!=null&&!"".equals(EA_TIME))
sql.append(" and t.EA_TIME='"+EA_TIME+"'");
if (RIVERNAME!=null&&!"".equals(RIVERNAME))
sql.append(" and t.RIVERNAME='"+RIVERNAME+"'");
if (C_LOCUS!=null&&!"".equals(C_LOCUS))
sql.append(" and t.C_LOCUS='"+C_LOCUS+"'");
if (D_DATE!=null&&!"".equals(D_DATE))
sql.append(" and t.D_DATE='"+D_DATE+"'" );
al=db.executeQuery(sql.toString());
mp.setPageData("cny",al);
al = (ArrayList)mp.getPageData("cny");
mp.setTotalSize(al.size());
for (i=mp.getStartRowNo();i<mp.getEndRowNo();i++){
altemp = (ArrayList)al.get(i);
%>
<tr class='<%=(i%2==0)?"tr1":"tr2"%>'><!--三目运算符-->
<td><a href="DISSENSION2.jsp?ID=<%=altemp.get(13)%>"><%=altemp.get(1)%></a></td>
<td><%=altemp.get(3)%></td>
<td><%=altemp.get(8)%></td>
<td><%=altemp.get(4)%></td>
<td><%=altemp.get(10)%></td>
<td><%=altemp.get(12)%></td>
</tr>
<%}%>
<tr class=trbottom>
<td colspan="6"><%=mp.getNavigation("DISSENSION.jsp")%></td>
</tr>
</table>
</body>
</html>
[此贴子已经被作者于2006-9-22 15:37:10编辑过]
----------------解决方案--------------------------------------------------------