![](/img/trans.png)
[英]java.sql.SQLException: Parameter index out of range - whitespaces in String
[英]java.sql.SQLException: Parameter index of 9 is out of range (1, 8)
我有一個要求,我必須使用三個IN參數和6個OUT參數調用MySql存儲過程。
程序
DELIMITER $$
DROP PROCEDURE IF EXISTS GET_PRODUCT_INFO $$
CREATE PROCEDURE GET_PRODUCT_INFO(IN productName varchar(25),
IN divisionID int(11), IN productQuantity int(11),
OUT Price double, OUT price_without_vat double,
OUT vat double, OUT Quantity int, OUT ProductsId int, OUT ExpDate date)
BEGIN
select I.quantity into Quantity from ProductInventory I
where I.pname=productName and I.divid=divisionID ;
if Quantity > productQuantity THEN
select P.productID,P.price,P.price_without_vat,P.vat, I.quantity,P.ExpiryDate
into ProductsId,Price,price_without_vat,vat,Quantity,ExpDate
from product P,ProductInventory I
where P.pname=productName and I.pname=productName
and P.orgid=divisionID and I.divid=divisionID ;
update productinventory
set quantity=(quantity-productQuantity)
where pname=productName and divID=divisionID;
END IF;
END $$
call GET_PRODUCT_INFO('Crocin',1,2,@Price,@price_without_vat,@vat,@Quantity,@ProductsId,@ExpiryDate)$$
在這里,我能夠在mysql cmd提示符下檢索記錄...但是,每當我嘗試從JDBC代碼調用該過程時,都會收到此錯誤
例外
java.sql.SQLException:參數索引9超出com.mysql.jdbc.CallableStatement.checkParameterIndexBounds(CallableStatement.java:1002)的com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java)的范圍(1,8) :971)
callableStatement = (CallableStatement)con.prepareCall("{call GET_PRODUCT_INFO(?,?,?,?,?,?,?,?,?)}");
callableStatement.setInt(2, 1);
callableStatement.setInt(3, quantity);
callableStatement.registerOutParameter(4, Types.DOUBLE);
callableStatement.registerOutParameter(5, Types.DOUBLE);
callableStatement.registerOutParameter(6, Types.DOUBLE);
callableStatement.registerOutParameter(7, Types.INTEGER);
callableStatement.registerOutParameter(8, Types.INTEGER);
callableStatement.registerOutParameter(9, Types.DATE);--->Exception here
callableStatement.setString(1, "SomeText");
也包括這個。 您錯過了1
參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.