Informix存储过程和Java executeUpdate

时间:2013-07-22 13:26:28

标签: java stored-procedures informix

当然,我想知道在调用executeUpdate时有多少行受到影响。 我的executeUpdate调用执行插入的存储过程。我试图返回和int,但我得到“返回太多的值”,即使它只是返回一个int

我只想返回受影响的行数

爪哇:

    String pro ="{call pro_insert(?,?,?)}";
     CallableStatement callableStatement =
     dbConn.prepareCall(pro);
     callableStatement.setString(1,"9600111");
     callableStatement.setInt(2,1);
     callableStatement.setInt(3,100);                       
     Integer id = callableStatement.executeUpdate();

的Informix

CREATE PROCEDURE pro_insert ( source varchar(11), request_type_id smallint,result_code_id smallint  )
    RETURNING int ;

        INSERT INTO pro_table
        (
            source,request_type_id,result_code_id,time          
        )
        VALUES
        (
            source,request_type_id,result_code_id,CURRENT
        );

        return dbinfo('sqlca.sqlerrd2'); /* return number of rows affected */               
END PROCEDURE    

1 个答案:

答案 0 :(得分:1)

试试这个

String pro ="{? = call pro_insert(?,?,?)}";
CallableStatement callableStatement = dbConn.prepareCall(pro);
callableStatement.registerOutParameter(1, Types.Integer);
callableStatement.setString(2,"9600111");
callableStatement.setInt(3,1);
callableStatement.setInt(4,100);                       
callableStatement.execute();
int res = callableStatement.getInt(1);