1

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..

3
  • The procedure is named SaveLabourDetailsHead and you call SaveLabourWageDetails, that might be the problem. Commented Oct 25, 2013 at 5:54
  • Shouldn't that be {? = CALL SaveLabourDetailsHead(?)} Commented Oct 25, 2013 at 6:00
  • I made a simple mistake.. and spoiled lot of time.. thanks alot Commented Oct 25, 2013 at 6:01

6 Answers 6

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

int lastIsertId=cs.getInt(2);

Comments

0

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.

Comments

0

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;

Comments

0

I was chasing this for ages, then found out I'd missed and underscore from the name of the stored procedure! I didn't even have a procedure with the incorrect name.

What a stupid error message!

"The parameter is wrong - ooh, by the way, that procedure doesn't exist"

Comments

0

I was getting this error because procedure was not creatd at all in database. I created procedure after that it started to work. Point is sometimes error is misleading not showing the actual error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.