在利用PL/SQL存储过读取数据在JSP上打印出错
过程包如下:
create or replace package pagination_package as
type guestbook_cursor_type is ref cursor;
end pagination_package;
//***************************************************************************//
//****************************************************************************//
create or replace procedure emp_page
(
tableName in varchar2, --表名
page_size in number, --每页显示记录数
pageNow in number, --当前页
myrows out number, -- 总记录数
myPageCount out number, --总页数
my_cursor out pagination_package.guestbook_cursor_type --返回的结果集
)
is
v_sql varchar2(1000);
v_begin number := (pageNow-1)*page_size+1;
v_end number := pageNow*page_size;
begin
v_sql:='select * from (select e.*,rownum rn from (select * from '||tableName||')e where rownum<='||v_end||')where rn>='||v_begin;
open my_cursor for v_sql;
v_sql:='select count(*) from '||tableName;
execute immediate v_sql into myrows;
if mod(myrows,page_size)=0 then myPageCount:= myrows/page_size;
else myPageCount:= myrows/page_size+1;
end if;
end;
//***************************************************************************//
//****************************************************************************//
jsp代码如下:
<%Connection conn=null;
ResultSet rs=null;
CallableStatement cs=null;
try{
Class.forName("oracle.jdbc.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger");
cs=conn.prepareCall("{call emp_page(?,?,?,?,?,?)}");
// 表名
cs.setString(1,"scott.emp");
//每页显示记录条数
cs.setInt(2,5);
//String page_Ye=request.getParameter("page_ye");
//显示第几页的记录
//cs.setInt(3,Integer.parseInt(page_Ye));
cs.setInt(3,1);
//总记录数
cs.registerOutParameter(4,oracle.jdbc.OracleTypes.NUMBER);
//总页数
cs.registerOutParameter(5,oracle.jdbc.OracleTypes.NUMBER);
//游标
cs.registerOutParameter(6,oracle.jdbc.OracleTypes.CURSOR);
cs.execute();
int recordNum=cs.getInt(4);
int pageNum=cs.getInt(5);
out.println(recordNum);
out.println(pageNum);
rs = (ResultSet)cs.getObject(6);
out.println(recordNum);
out.println(pageNum);
while(rs.next()){
out.print("<tr>");
out.print("<td>"+rs.getInt(1)+"</td><td>"+rs.getString(2)+"</td>");
out.print("</tr>");
}
for(int i=1;i<=pageNum;i++)
{
out.print("<a href=Proicedure.jsp?page_ye="+i+">["+i+"]</a>");
}
}catch(Exception e){
e.printStackTrace();
}
finally{
try{
//rs.close();
conn.close();
cs.close();
} catch (
SQLException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
}
%>
ResultSet数据集报错;
------解决方案--------------------
用这个试试ResultSet rs=cstat.getResultSet();