从 Java JDBC 驱动程序调用 MySQL 中的存储过程时,我偶尔会遇到一个奇怪的异常。我的应用程序代码如下所示:
int newID = 0;
if (myObj != null)
newID = myObj.getId(); //getId() returns an int value...
CallableStatement stmt = conn.prepareCall("{CALL MySP(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}");
stmt.registerOutParameter(14, Types.INTEGER);
stmt.registerOutParameter(15, Types.BIT);
stmt.setShort(1, status);
... // other setters for each parameter of the stored procedure
stmt.setInt(14, newID);
stmt.execute();
newID = stmt.getInt(14);
createdNew = stmt.getBoolean(15);
执行语句在 99% 的情况下都会成功,除了少数情况下引发异常:
java.sql.SQLException: Incorrect integer value: '@com_mysql_jdbc_outparam_13' for column '_NewID' at row 1
编辑:这是存储过程的主体:
delimiter $$
CREATE PROCEDURE `AddPhysNode`(
IN _a SMALLINT,IN _b BIGINT,IN _c BIT,IN _d VARCHAR(255),IN _e LONGBLOB,IN _f LONGBLOB,IN _g INT,IN _h SMALLINT,IN _i SMALLINT,IN _l SMALLINT,
IN _m BIT,IN _n INT,IN _o BIGINT,INOUT _NewID INT,OUT _CreatedNew BIT
)
BEGIN
IF (_NewID > 0) THEN
UPDATE tbl
SET a = _a
WHERE Id = _NewID;
SET _CreatedNew = 0;
ELSE
INSERT INTO tbl (`a`,`b`,`c`,`d`,`e`,`f`,`g`,`h`,`i`,`l`,`m`,`n`,`o`)
VALUES (_a,_b,_c,_d,_e,_f,_g,_h,_i,_l,_m,_n,_o);
SET _CreatedNew = 1;
SET _NewID = @@IDENTITY;
END IF;
END$$
对此有任何提示吗?
非常感谢你!
最好的
盖尔西