使用out参数调用存储过程时出现此错误。它指向我注册out参数的位置。我不知道我在这里缺少什么。提前致谢。
java.sql.SQLException:参数号6不是OUT参数
这是我在Java中的方法:
String sp = "{CALL `hotelbuddy2.0`.`reservation.newres`(?,?,?,?,?,?)}";
CallableStatement cs = DB2.con2.prepareCall(sp);
cs.setInt(1, guest.getGuestId());
cs.setTimestamp(2, checkIn);
cs.setTimestamp(3, checkOut);
cs.setString(4, comment);
cs.setString(5, UserDetails.username);
cs.registerOutParameter(6, Types.INTEGER);
cs.execute();
reservationId = cs.getInt(6);
cs.close();
这是我在Mysql中的存储过程:
CREATE DEFINER=`root`@`localhost` PROCEDURE `reservation.newres`(
IN p_guest_id INT,
IN p_check_in TIMESTAMP,
IN p_check_out timestamp,
IN p_comment VARCHAR(300),
IN p_created_by VARCHAR(45),
OUT p_reservation_id INT
)
BEGIN
INSERT INTO reservation
SET guest_id = p_guest_id,
check_in = p_check_in,
check_out = p_check_out,
`comment` = p_comment,
created_by = p_created_by;
SELECT LAST_INSERT_ID() INTO p_reservation_id;
END