简体   繁体   中英

java.sql.SQLException: Parameter index of 9 is out of range (1, 8)

I have a requirement where I have to call a MySql Stored Procedure with three IN parameters and 6 OUT parameters.

PROCEDURE

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)$$

Here I am able to retrieve the record in mysql cmd prompt... But whenever I am trying to call the procedure from my JDBC code am getting this error

EXCEPTION

java.sql.SQLException: Parameter index of 9 is out of range (1, 8) at com.mysql.jdbc.CallableStatement.checkParameterIndexBounds(CallableStatement.java:1002) at com.mysql.jdbc.CallableStatement.checkIsOutputParam(CallableStatement.java: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");

Include this too. You've missed out 1 parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM