Hello,
I have a stored procedure that inserts a new passenger into a database. The fields are name and email. The passengerID is a auto increment. The database I am using is mySQL.
The problem is that I want to return the passengerID when the stored procedure is called. I am not sure if that is possible. Here is my code:
Store procedure in mysql
The stored procedure is called from a java program below:Code:DELIMITER $$ DROP PROCEDURE IF EXISTS `flightdb`.`spInsertNewPassenger`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `spInsertNewPassenger`(_name varchar(50), _email varchar(5) ) BEGIN INSERT INTO Passengers ( name, email ) VALUES ( _name, _email ); END$$ DELIMITER ;
Can anyone help change the above code so that i can return the ID number.Code:try { CallableStatement cs = conn.prepareCall( "{ spInsertNewPassenger( ?, ?) }" ); cs.setString( 1, name ); cs.setString( 2, email ); cs.executeUpdate(); //I want to return the ID here }
Thanks in advance,
Steve




Reply With Quote