Reputation: 259
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..
Upvotes: 1
Views: 13776
Reputation: 10947
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.
Upvotes: 0
Reputation: 36
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"
Upvotes: 0
Reputation: 173
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;
Upvotes: 0
Reputation: 167
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.
Upvotes: 0
Reputation: 12983
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
.
Upvotes: 2
Reputation: 8337
Your out parameter is of type String, but it should be int. Try this out.
int lastIsertId=cs.getInt(2);
Upvotes: 0