81,092
社区成员
发帖
与我相关
我的任务
分享
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.util.*"%>
<%@page import="org.json.*"%>
<%@page import="util.DB"%>
<%
// String pageNum= request.getParameter("pageNum") ;//获取用户要显示的页数
String pageNum="1";//获取用户要显示的页数
int curPage=0;
if(pageNum==null){
pageNum="1";
}
try{
curPage=Integer.parseInt(pageNum);
}catch(NumberFormatException e){
curPage=1;
}
int pageSize=20; //每页显示数
DB db=new DB(); //实例化数据库连接
String sqlStr = "SELECT e.*,d.Bname FROM BOOK e LEFT JOIN BOOK_STYLE d ON e.Bno=d.Bno";
ResultSet rs=db.query(sqlStr);
rs.last(); //将游标移到最后一行
int total=rs.getRow(); //总记录数
int totalPage=(total%pageSize==0)?(total/pageSize):(total/pageSize+1); //总页数
int position=(curPage-1)*pageSize+1;
//rs.absolute(position);
int mn=position+pageSize; //把结果集指针移到当前页应该显示的记录的开始
JSONArray array = new JSONArray(); //构造数组
JSONObject jsonObj=new JSONObject();
jsonObj.put("total", total);
jsonObj.put("pageSize", pageSize);
jsonObj.put("totalPage", totalPage);
array.put(jsonObj);
String sqlStr1 = "select * from (select ROWNUM r,e.*,d.Bname FROM BOOK e, BOOK_STYLE d where e.Bno=d.Bno and rownum<21) t2 where t2.r>=1";
ResultSet rs1=db.query(sqlStr);
out.println(rs1);//打印结果
while(rs.next()){
ResultSetMetaData metaData = rs.getMetaData(); // 获取列数
int columnCount = metaData.getColumnCount();
for (int i = 1; i <= columnCount; i++) {
String columnName =metaData.getColumnLabel(i);
String value = rs.getString(columnName);
jsonObj.put(columnName, value);
}
array.put(jsonObj);
}
String result=array.toString();
out.println(result);打印结果
response.getWriter().write(result);
%>