0

我有这个存储过程:

ALTER PROCEDURE dbo.getRegionsInArea
    (
    @areaID int,
    @ID int OUTPUT,
    @name varchar(50) OUTPUT
    )
AS
BEGIN
    SET NOCOUNT ON
    SELECT @ID = [ID], @name = [name] FROM Region
    WHERE areaID = @areaID
    END

我想从JDBC.

问题g

如何获取变量输出的所有值,ID因为name存储过程会返回它们的许多值。

我试过的

Connection con = Database.getConnection();
            String storedProcedure = "{call getRegionsInArea (?,?,?)}";
            CallableStatement callableStatement = null;
            try {
                callableStatement = con.prepareCall(storedProcedure);
                callableStatement.setInt(1, getID());
                callableStatement.registerOutParameter(2,
                        java.sql.Types.INTEGER);
                callableStatement.registerOutParameter(3,
                        java.sql.Types.VARCHAR);
                callableStatement.execute();
                    System.out.println("ID = " + callableStatement.getInt(2));
                    System.out.println("name = "
                            + callableStatement.getString(3));

问题

ID我刚刚收到and的最后一个值name

请有任何帮助

4

1 回答 1

2

试试这个解决方案:

callableStatement = con.prepareCall(storedProcedure); 
callableStatement.setInt(1, getID()); 
callableStatement.execute(); 
ResultSet resultSet = callableStatement.getResultSet(); 
while (resultSet.next()) { 
   int returnedID = resultSet.getInt(1); 
   String returnedName = resultSet.getString(2);   
}

并改变你的SP,如:

ALTER PROCEDURE dbo.getRegionsInArea 
( 
@areaID int
) 
AS 
BEGIN 
SET NOCOUNT ON 
SELECT [ID],[name] FROM Region 
WHERE areaID = @areaID 
END
于 2013-04-29T08:07:47.260 回答