Connection connection;
    CallableStatement stmt;
    ...    String sql = "{ call sp_temp(?) }";
    stmt = connection.prepareCall(sql);
    stmt.registerOutParameter(1,Types.INTEGER);    stmt.execute();
    
    System.out.printline(stmt.getInt(1));

解决方案 »

  1.   

    Connection connection;
        CallableStatement stmt;
        ...    String sql = "{ call sp_temp(?) }";
        stmt = connection.prepareCall(sql);
        stmt.registerOutParameter(1,Types.INTEGER);    stmt.execute();
        
        System.out.printline(stmt.getInt(1));
      

  2.   

    Connection connection;
        CallableStatement stmt;
        ...    String sql = "{ call sp_temp(?) }";
        stmt = connection.prepareCall(sql);
        stmt.registerOutParameter(1,Types.INTEGER);    stmt.execute();
        
        System.out.printline(stmt.getInt(1));
      

  3.   

    CallableStatement stmt=con.prepareCall("{call sp_temp[(?)]}");
    stmt.registerOutParameter(1,java.sql.Types.INTEGER);
    ......................
    int a =stme.getInt(1);
      

  4.   

    [引用JDBC SPEC的原文:]
    OUT Parameters:
    The method registerOutParameter must be called to set the type for each OUT
    parameter before a CallableStatement object is executed. When the stored
    procedure returns from execution, it will use these types to set the values for any OUT parameters.
    The values of OUT parameters can be retrieved using the appropriate getter
    methods defined in the CallableStatement interface. CODE EXAMPLE shows the execution of a stored procedure with two OUT parameters, a string and float,
    and the retrieval of the OUT parameter values.CallableStatement cstmt = conn.prepareCall(
    “{CALL GET_NAME_AND_NUMBER(?, ?)}");
    cstmt.registerOutParameter(1, java.sql.Types.STRING);
    cstmt.registerOutParameter(2, java.sql.Types.FLOAT);
    cstmt.execute();
    // Retrieve OUT parameters
    String name = cstmt.getString(1);
    float number = cstmt.getFloat(2);