此后留白
2019-07-01 19:50
采纳率: 100%
浏览 679
已结题

java调用没有输出参数的存储过程获取返回结果集?

Java后台

sqlserver2008r2数据库

最后一个 ‘call1’那个存储过程。

public void getlist() throws Exception 
    {   
        Connection dao = JdbcConnection.getConn();


        String call = "{call Sc_ljycfwq(?, ?, ?, ?)}";
        CallableStatement callStatement = dao.prepareCall(call);
        callStatement.setString(1, "air");
        callStatement.setString(2, "XX.XX.XX.XXX");
        callStatement.setString(3, "sa");
        callStatement.setString(4, "XXXXXXXXX");
        callStatement.execute();
        callStatement.close();

        String call2 = "{call sp_serveroption(?, ?, ?)}";
        callStatement = dao.prepareCall(call2);
        callStatement.setString(1, "air");
        callStatement.setString(2, "rpc out");
        callStatement.setString(3, "true");
        callStatement.execute();
        callStatement.close();

        String call1 = "{call air.[XXX].dbo.sp_executesql(?, ?, ?, ?, ?, ?)}";
        callStatement = dao.prepareCall(call1);
        callStatement.setString(1, "exec rpt_MastCashRpt @P1,@P2,@P3,@P4");
        callStatement.setString(2, "@P1 varchar(20),@P2 varchar(20),@P3 varchar(4000),@P4 int");
        callStatement.setString(3, "2019-07-01");
        callStatement.setString(4, "2019-07-31");
        callStatement.setString(5, "(m.moneyid=0) and  1=1");
        callStatement.setInt(6, 0);
        callStatement.execute();
        callStatement.close();
        dao.close();

    }

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • 此后留白 2019-08-27 17:29
    最佳回答
    //Start
                String call1 = "{call "+randString+".[XXX].dbo.sp_executesql(?, ?, ?, ?, ?, ?)}";
                callStatement = dao.prepareCall(call1);
                callStatement.setString(1, "exec ‘存储过程名称’ @P1,@P2,@P3,@P4");
                callStatement.setString(2, "@P1 varchar(20),@P2 varchar(20),@P3 varchar(4000),@P4 int");
                callStatement.setString(3, dateString);//dateString);
                callStatement.setString(4, dateString);
                callStatement.setString(5, "(m.moneyid=0) and  1=1");
                callStatement.setInt(6, 0);
                callStatement.execute();
                //取数(要在关闭之前操作数据)
                ResultSet rrs = callStatement.getResultSet();//先搞出来一个结果集
                    while (rrs.next()) {
                    //最原始的取值
                    temp.put("xxx", rrs.getString("xxx"));//
                    temp.put("xxx", rrs.getString("xxx"));//
                    temp.put("xxx", rrs.getString("xxx"));//
                }
    
                callStatement.close();
                //END
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题