日期:2014-05-20  浏览次数:20796 次

用游标做的分页存储过程,如何取出记录集呢
我附上我的存储过程:数据库是MSSql
CREATE   PROCEDURE   infopagelist
@currentpage   int,@keyword   varchar(100)
as

SET   NOCOUNT   ON
Declare   @p1   int,@rowcount   int,@pagesize   int,@sqlstr   varchar(1000)
set   @pagesize=40
set   @sqlstr= 'select   id,title   from   T_info '
if   @keyword!= ' '   begin
set   @sqlstr=@sqlstr+ '   where   title   like   ' '% '+@keyword+ '% ' ' '
end
set   @sqlstr=@sqlstr+ '   order   by   id   desc '

exec   sp_cursoropen   @p1   output,@sqlstr,@scrollopt=1,@ccopt=1
--select   ceiling(1.0*@rowcount/@pagesize)   as   totalpage
set   @currentpage=(@currentpage-1)*@pagesize+1
exec   sp_cursorfetch   @p1,16,@currentpage,@pagesize
exec   sp_cursorclose   @p1
set   nocount   off
GO
如何取出记录集呢,我试两天了,也找了相关资料,一直没有成功,请求达大帮忙.

------解决方案--------------------
没有人知道怎么调用嘛,请高手给些帮助
------解决方案--------------------
create or replace procedure P_YJ_YJGL //数据库oracle
(
AS_YHM IN VARCHAR2, --用户名
AS_NSRSBH IN VARCHAR2, --纳税人识别号
AS_LX IN VARCHAR2, --类型
RC_GLJG OUT WEB_WSSB.PKG_TYPES.REF_CURSOR)
is
ac_msg varchar2(30);

begin
OPEN RC_GLJG FOR
SELECT ac_msg FROM DUAL; //得到记录集
end P_YJ_YJGL;

------解决方案--------------------
import java.sql.*;

public class Test Conn{

private Connection getConn(){
Connection conn = null;
try {
Class.forName( "org.gjt.mm.mysql.Driver ");
try {
conn = DriverManager.getConnection( "jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&
characterEncoding=GBK ", "root ", "ntsky ");
} catch (SQLException e1) {
e1.printStackTrace();
}
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
return conn;
}

public void testC() {
Connection conn = getConn();
ResultSet rs = null;
CallableStatement cs = null;
String a = null;
try {
CallableStatement cStmt = conn.prepareCall( "{call p_test()} ");
cStmt.executeUpdate();
} catch (Exception e) {
System.out.println( "hahad " + e.getMessage());
} finally {
try {
conn.close();
} catch (Exception ex) {
System.out.println( "ex : " + ex.getMessage());
}
}

}

public static void main(String[] args) {
new TestConn().testC();
}
}