Results 1 to 2 of 2

Thread: sending parameters to a stored procedure in MySQL [*Resolved*]

Threaded View

  1. #1

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

    Resolved sending parameters to a stored procedure in MySQL [*Resolved*]

    Hello,

    I want to use a stored procedure to mysql to insert a new airport.
    This is the code I am using, it runs ok but I get an error say that the
    syntax in the stored procedure is incorrect. I have tested the stored procedure
    in mySql and it worked fine. But doesn't work when l call it from my java program.

    This is the java code.
    Code:
    try 
    {
    	PreparedStatement cs = conn.prepareStatement("{call spInsertNewAirport(?,?,?}");
    	cs.setString(1, airportCode);
    	cs.setString(2, airportName);
    	cs.setString(3, country);
    	cs.executeUpdate();
    } 
    catch (SQLException sqle)	
    {
    	System.err.println("\nSQLException:\n");
    	System.err.println("SQLState: "+sqle.getSQLState());
    	System.err.println("Message: "+ sqle.getMessage());
    }
    I am using Jcreator to develop this program. I was using the callable object but got a message
    saying it was not supported. So I have tried using the preparedStatement instead.

    For more information this is the stored procedure in mysql
    Code:
     DELIMITER $$
    
    		DROP PROCEDURE IF EXISTS `flightdb`.`spInsertNewAirport`$$
    		
    		CREATE PROCEDURE `flightdb`.`spInsertNewAirport` (_airportCode varchar(10), _airportName varchar(20), _country varchar(20))
    			
    			
    		BEGIN
    			INSERT INTO Airport (AirportCode, AirportName, Country)
    			VALUES (_airportCode, _airportName, _country);
    		END$$
    		
    		DELIMITER ;
    Many thanks in advance,

    Steve
    Last edited by steve_rm; Sep 4th, 2006 at 10:28 PM.
    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