JDBC调用Sybase存储过程,无法得到结果集!
java代码部分如下:
String sproc = "{ call zhouxiaobotest2(?,?,?,?)} ";
CommonDAO dao = null;
try {
dao = new CommonDAO(jndi);
Connection connect = dao.getConn();
//得到总数
rowNum = PageDiv.getCount(countSql.toString(), dao);
//设置分页信息
pageBean.setPageInfo(rowNum, pageSize);
// 获取CallableStatement语句:
CallableStatement mStatement = connect.prepareCall(sproc,
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
// 传入输入参数和注册输出参数
mStatement.setString(1,sql.toString());
mStatement.setInt(2, 10);
mStatement.setInt(3, 10);
mStatement.setInt(4, 5000);
// 执行存储过程
ResultSet rs = null;
mStatement.execute();
rs = mStatement.getResultSet();
catch (Exception ex) {
ex.printStackTrace();
logger.warn(sql.toString());
} finally {
dao.destroy();
dao = null;
sproc = null;
}
存储过程如下:
create procedure zhouxiaobotest @qry varchar(16384),@ipage int, @num int,@maxpages int
as
/*@qry SQL语句, @ipage 页数, @num 每页记录条数, @maxpages 最大查询页数 */
begin
declare @execsql varchar(16384)
set @execsql = " select USER_NAME from TBL_USER "
execute (@execsql)
end
create procedure zhouxiaobotest2 @qry varchar(16384),@ipage int, @num int,@maxpages int
as
/*@qry SQL语句, @ipage 页数, @num 每页记录条数, @maxpages 最大查询页数 */
begin
select USER_NAME from TBL_USER
end
现在我的问题是调用存储过程zhouxiaobotest,mStatement.execute()始终是false;而调用zhouxiaobotest2 mStatement.execute()就是true,能得到结果集。我想知道如何修改程序使我能够调用zhouxiaobotest取得结果集(之前调试程序运行没有抛出任何异常,而且控制台运行存储过程也都正确)
[解决办法]
看看这里有解答 http://www.haolla.com/girls