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:
Can anyone help change the above code so that i can return the ID number.
Thanks in advance,
Steve
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
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 ;
The stored procedure is called from a java program below:
Code:
try
{
CallableStatement cs = conn.prepareCall( "{ spInsertNewPassenger( ?, ?) }" );
cs.setString( 1, name );
cs.setString( 2, email );
cs.executeUpdate(); //I want to return the ID here
}
Can anyone help change the above code so that i can return the ID number.
Thanks in advance,
Steve