欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

开发类 - Jdbc 调用 SQL SERVER 2008 存储过程

程序员文章站 2022-07-14 18:24:12
...

1.Java示例:

    public void saveType9Cnt(String sbm, String sblx){

        String sSQL = " exec dzzhType9Cnt '" + sbm + "' ";

        CallableStatement cs = null;
        ResultSet rs = null;

        try {
            conn = JdbcUtil.findConnection();
            cs = conn.prepareCall(sSQL);
            rs = cs.executeQuery();
            if(rs.next()){

                TypeAllCnt typeAllCnt = new TypeAllCnt();

                typeAllCnt.setImei(rs.getString("imei"));
                typeAllCnt.setType(sblx);

                typeAllCnt.setField1(rs.getString("minRainfall"));
                typeAllCnt.setField2(rs.getString("hourRainfall"));
                typeAllCnt.setField3(rs.getString("dayRainfall"));
                typeAllCnt.setField4(rs.getString("weekRainfall"));
                typeAllCnt.setField5(rs.getString("monthRainfall"));

                saveType9Cnt(typeAllCnt, conn);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JdbcUtil.close(cs, conn);
        }
    }

2.需要在 SQL SERVER 2008 存储过程中加入,否则会提示没有返回结果集:

set nocount on;

  

 

相关标签: 开发类