http://www.csdn.net/expert/topic/227/227106.xml?temp=.5372431

解决方案 »

  1.   

    此例返回值是int型。至于数据库的连接于Sql语句的执行你应该没问题。
    String SqlStr = "declare @xx int  Exec @xx=ProcName  Select @xx";
    ResultSet rs = DB.getResultSet(SqlStr);
    rs.next();
    p = rs.getInt(1);
    rs.close();
    p即为返回值。
      

  2.   

    使用java.sql.CallableStatement来调用存储过程.
    CallableStatement cstmt = con.prepareCall({?=call procedureName(?,?,?....)});
    ?=这个是返回的数值,如果存储过程没有返回,那么就省略他,同样,如果有多少参数就写多少?号.
    如果有返回值那么需要调用注册方法.
      

  3.   

    哎呀!楼上的我就不懂返回值怎样注册,
    和在java中怎样将这个返回值赋给变量?
    你怎么不说清楚一点呢?我很焦急哦!!!
    谢谢
      

  4.   

    1.无参数调用方式
    //Storeprocedure 为存储过程名
    CallabelStatement cstm = con.prepareCall("{call Storeprocedure()}");
    ResultSet rs = cstm.executeQuery();2.有参数调用方式//Storeprocedure 为存储过程名
    CallabelStatement cstm = con.prepareCall("{call Storeprocedure(?,?)}");
    //登记输出参数,根据参数类型不同而改变java.sql.Types的值
    cstm.registerOutParameter(1,java.sql.Types.TINYINT);
    cstm.registerOutParameter(2,java.sql.Types.DECIMAL,2);
    //执行
    cstm.executeUpdate();
    //获取输出参数的值
    byte x = cstm.getByte(1);
    Numeric n = cstm.getNumeric(2,2);