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个回答

//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
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐