当前位置:编程学习 > JSP >>

帮忙分析下一下这段jsp分页查询代码!主要是String sql和public int queryCount里面的代码不是很清楚

public class UserAction { MyConnectionDB connectionDB=new MyConnectionDB(); private ResultSet res=null; private List<UserInfo> userList=new ArrayList(); public List<UserInfo> selectUser(int pageNum){ int start=(pageNum-1)*3+1; int end=(pageNum-1)*3+3; String sql="select * from (SELECT ROW_NUMBER() OVER" +"(order by userId)as number,* " +"FROM UserInfo) as f where " +"f.number between "+start+ " and "+end; connectionDB.getConnectionDB(); res=connectionDB.queryData(sql); try { while (res.next()) { UserInfo user=new UserInfo(); user.setUserId(res.getInt(1)); user.setUserName(res.getString("userName")); user.setUserPwd(res.getString("userPwd")); user.setUserSex(res.getString(4)); user.setUserLive(res.getString(5)); user.setUserCity(res.getString(6)); userList.add(user); } } catch (SQLException e) { e.printStackTrace(); } connectionDB.closeConnection(); return userList; } public int queryCount(){ int count=0; String sql="select count(*) from UserInfo"; connectionDB.getConnectionDB(); res=connectionDB.queryData(sql); try { if(res.next()){ count=res.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } if(count%3==0){ count=count/3; }else{ count=count/3+1; } connectionDB.closeConnection(); return count; }
追问:
        	
				
那这里的ROW_NUMBER是不是有一个语法语句的?
row_number() over(order by userId)意思是先拍好序,再标行号。
答案:String sql="select * from (SELECT ROW_NUMBER() OVER" 
                     +"(order by userId)as number,* "
                     +"FROM UserInfo) as f where "
                     +"f.number between "+start+
                     " and "+end;
分页检索用。ROW_NUMBER() OVER(order by userId)as number这里可以起到先排序后标行号的作用。
整个sql文就是取结果集中行号start到end的记录。

这个方法public int queryCount里,sql文是取总件数的,返回值模3,估计是每页显示3件,则整个方法的返回值是总页数。
其他:>&seachkind<%=seachkind%>& 你这样传参数是不对的。等号哪里去了。
 >&seachkind<%=seachkind%>& 你这样传参数是不对的。等号哪里去了。
 

上一个:高分求解下列JSP题目(请写出代码及数据库)?【程序调通后追加】
下一个:急求JSP的留言板原代码?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,