java调用mssql存储过程后,记录集的返回为null

tcrct 2007-03-02 03:07:54
存储过程:
create proc proc_pageList
(
@tabName varchar(100),
@columnName varchar(200),
@idName varchar(100),
@pageSize int,
@pageIndex int,
@pageCounts int output,
@rowCounts int output
)
as
select @rowCounts = count(*) from buymessageinfo--@tabName
set @pageCounts = Ceiling(@rowCounts *1.0 / @pageSize)
Declare @sql nvarchar(200)
if @pageIndex < @pageCounts
set @sql = 'Select '+@columnName+' from (select top '+ str(@pageSize) +' * from (select top '+ str(@pageIndex * @pageSize) +' * from buymessageinfo) as tab1 order by '+@idName+' desc) as tab2 order by '+@idName
else
set @sql = 'Select '+@columnName+' from (select top '+ str(@rowCounts-(@pageIndex-1)*@pageSize) +' * from (select * from buymessageinfo) as tab1 order by '+@idName+' desc) as ta2 order by '+@idName
exec (@sql)


java:
public static ArrayList execProcPageList(String procSql,String tableName,String colunm,String IdName,int pageSize, int pageIndex)
{
ArrayList al = new ArrayList();
try {
getConn();
cstmt = conn.prepareCall(procSql);
cstmt.setString(1,tableName);
cstmt.setString(2,colunm);
cstmt.setString(3, IdName);
cstmt.setInt(4, pageSize);
cstmt.setInt(5,pageIndex);
cstmt.registerOutParameter(6, java.sql.Types.INTEGER);
cstmt.registerOutParameter(7, java.sql.Types.INTEGER);
//cstmt.execute();
rs = cstmt.executeQuery();
rs = cstmt.getResultSet();
int pageCounts = cstmt.getInt(6);
int rowCounts = cstmt.getInt(7);
System.out.println(rs.next());
System.out.println(pageCounts);
System.out.println(rowCounts);
} catch (Exception e) {e.printStackTrace(); }
finally
{
try {
if(!conn.isClosed())
{
cstmt.close();
rs.close();
conn.close();
}
} catch (SQLException e) {e.printStackTrace();}
}
return al;

}

打印出来的结果:
false
4
14
0

为什么rs.next()这false的呢?基本上其它的方法都试过了。
...全文
395 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenwenya 2007-03-21
  • 打赏
  • 举报
回复
用短信猫做短信平台,比较稳定,不受网络安全影响,响应及时,适合一些重要的安全性高的业务需求,但是发送速度有限制,一般是800条/小时
sp短信通道发送速度快,但是由于接入的开发商很多,在服务器不多的情况下,必然会排队,有时繁忙时提交一条短信,第二天才能收到,而且网络不正常时,也会影响使用
建议一些管理软件用短信猫做短信平台
1.方寸GSM-Modem 短信平台

GSM-Modem 短信平台,无需联网,只需一台电脑,一个短信猫(或手机),一个短信开发接口,就可轻松建立短信服务器,可实现短信收发,短信互动等功能,一台电脑可以连接多个短信猫硬件,从而提高吞吐量。

2.方寸短信数据库接口(手机短信接口,短信二次开发控件)

通过本数据库接口,能使你现有的系统(如OA、CRM、ERP等系统)轻松实现无线办公功能,无论你用的是哪种开发语言(VB\VC\VFP\asp\jsp\java\pb\delphi...),只要你的系统能读写数据库即可对接!你仅需要在指定的表中添加记录,本接口程序就自动进行发送短信了,收到的短信会自动保存到数据库里,所以,您不需要了解任何有关数据通信方面的知识,就可实现手机短信的收发等功能!
电话:0755-25996144
联系人:陈先生
网址:http://www.fcwww.com
qq:393376247
jxl76219 2007-03-02
  • 打赏
  • 举报
回复
只是单一的使用调用储存分页功能,别的都去掉了,需要你自己完善!
jxl76219 2007-03-02
  • 打赏
  • 举报
回复
给你个oracle存储分页功能的:
create or replace procedure Show_Veh_pagination
(p_pageSize in int,
p_pageNo in int,
p_SqlSelect in varchar2,
p_SqlCountSelect in varchar2,
p_outCount out int,
p_outCursor out sys_refcursor)
is
v_sql varchar2(3000);
v_count int;
v_heiRowcount int;
v_lowRowcount int;
begin
p_outCount := 0 ;
if length(p_SqlCountSelect) > 0 then
execute immediate p_SqlCountSelect into v_count;
p_outCount := v_count;
end if;

v_heiRowcount := p_pageSize * p_pageNo;
v_lowRowcount := v_heiRowcount – p_pageSize + 1;

v_sql := ‘select t.* from
(select v.*,rownum as r from (‘||p_SqlSelect ||’) v
where rownum <= ‘|| v_heiRowcount ||’) t
where t.r >= ‘|| v_lowRowcount ||’’;

open p_outCursor for v_sql;
end Show_Veh_pagination;

//------在页面中的调用,因为我使用的是c#.net,所以,只能给你这个了
Oracleconnection Cn = new Oracleconnection(…..);
Cn.open();
DataTable dt = GetData(10,1,”select * from TableName order by column [ desc | asc ]”,Cn);
DataGrid.DataSouce = dt;
DataGrid.DataBind();

Private DataTable GetData (int pageSize,int pageNo,string sql,Oracleconnection cn)
{
Oraclecommand Comm. = new Oraclecommand();
Comm.connection = cn;
Comm..commandText = “Show_page”;
Comm..commandType = commandType. StoredProcedure;

Comm.Parameters.add(“p_pageSize”,Oracle.Float,50);
Comm.Parameters[“p_pageSize”].Direction = ParameterDirection.Intput;
Comm.Parameters[“p_pageSize”].Value = pageSize ;

Comm.Parameters.add(“p_pageNo”.OracleType.Float,50);
Comm.Parameters[“p_pageNo”].Direction = ParameterDirection.Intput;
Comm.Parameters[“p_pageNo”].Value = pageNo;

Comm.Parameters.add(“p_SqlSelect”,OracleType.VarChar,3000);
Comm.Parameters[“p_SqlSelect”].Direction = ParameterDirection.Intput;
Comm.Parameters[“p_SqlSelect”].Value = sql;

Comm.Parameters.add(“p_outRecordcount”,OraclType.Float);
Comm.Parameters[“p_outRecordcount”].Direction = ParameterDirection.Output;
Comm.Parameters[“p_outRecordcount”].Value = 0;

Comm.Parameters.add(“p_outReturnCursor”,OracleType.Cursor);
Comm.Parameters[“p_outReturnCursor”].Direction = ParameterDirection.Output;

OracleDataAdapter oDa = new OracleDataAdapter(Comm);
DataSet ds = new DataSet();
ODa.Fill(ds);

Lable.text = “共有记录 ”+int.parse(comm.Parameters[“p_outRecordcount”].Value.ToString())+” 条”;

Return ds.Table[0];
}
tcrct 2007-03-02
  • 打赏
  • 举报
回复
楼上的,返回的值已经打印出来了,只不过不知道为什么记录集没有返回出来。其中4,14是在存储过程里是output的。现在要的是记录集。请帮帮忙!
vacuumboy 2007-03-02
  • 打赏
  • 举报
回复
你的方法用错了,首先要用registerOutParameter方法注册你要返回的参数,给你个例子吧
public String getSQL(String message_id){
String result = "";
String sql = "{call dbo.usp_generate_filter_query(?,?)}";
Connection conn = null;
CallableStatement cstmt = null;
try{
conn = ConnectionManager.getConn(GlobalSettings.CLIENT_ADMIN_DB);
cstmt = conn.prepareCall(sql);
cstmt.setInt(1,Integer.parseInt(message_id));
cstmt.registerOutParameter(2,Types.VARCHAR);
cstmt.execute();
result = cstmt.getString(2);
cstmt.close();
ConnectionManager.close(conn);
}catch(Exception e){
logger.debug("Exception in getSQL in SqlFunc");
ConnectionManager.close(conn);
e.printStackTrace();
}
return result;
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧