简体   繁体   中英

java.sql.SQLException: Parameter number 2 is not an OUT parameter

I am getting an Error while running this:

1. cs = getCon1().prepareCall("{CALL SaveLabourWageDetails(?,?)}");

2. cs.setString(1, user.getUserId());

3. cs.registerOutParameter(2, java.sql.Types.INTEGER); //<--- ERROR at this line

4. cs.execute();

5. String lastIsertId=cs.getString(2);

The Stored Procedure is :

CREATE

    PROCEDURE `cheque_alert`.`SaveLabourDetailsHead`(IN wage_entered_by VARCHAR(10),OUT LastInsertId INT)

    BEGIN
    INSERT INTO `cheque_alert`.`labour_wage_head`
            (
             `wage_entered_by`,
             `entered_date_time`)
    VALUES (wage_entered_by,
         NOW());

          SELECT LAST_INSERT_ID() INTO LastInsertId;

    END$$

DELIMITER ;

Please point out the problem in this code..

You are calling wrong procedure. You have procedure SaveLabourDetailsHead and you are calling

1. cs = getCon1().prepareCall("{CALL SaveLabourWageDetails(?,?)}");  
                                         ↑  

Change to,

1. cs = getCon1().prepareCall("{CALL SaveLabourDetailsHead(?)}");  

Set String parameter wage_entered_by .

Your out parameter is of type String, but it should be int. Try this out.

int lastIsertId=cs.getInt(2);

I had the same problem but the output exception is misleading as the root cause was the procedure name.

I typed incorrect procedure which did not exist in database.

Instead of providing a SQL exception something like "routine does not exist", it gave:

java.sql.SQLException: Parameter number 2 is not an OUT parameter.

Just had the same problem.

It was a permission issue in my case. The MySQL user my application uses lacked the EXECUTE permission on the schema I'm working on.

GRANT EXECUTE ON <your_schema>.* TO '<your_user>'@'localhost';
FLUSH PRIVILEGES;

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