Results 1 to 2 of 2

Thread: Return value from a insert stored procedure

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Return value from a insert stored procedure

    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
    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
    Last edited by steve_rm; Sep 21st, 2006 at 07:12 AM.
    steve

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width