Mysql inserts in stored procedure slow over Java MysqlConnector
===

I am seeing mysql insert times performing orders of magnitude slower when called over JDBC when compared to calling from an IDE or on the mysql command line and was wondering if anyone could point me in the right direction.

I am running everything locally, so network latency should not be an issue. 

I created the following very contrived example to illustrate the point.

I created a stored procedure that takes in a single INT and inserts it into a table:

    DELIMITER $$
    
    CREATE PROCEDURE testInsert(IN input INT)
    BEGIN
    		INSERT INTO test_table(column_1, column_2) 
    		VALUES(input, input);
    		
        END$$
    
    DELIMITER ;

If I were to call this procedure from the command line or a mysql IDE (I am using SQLyog):

    CALL testInsert(0);

The procedure call happens, for all intents and purposes, instantly:
    
    Execution Time : 0.007 sec
    Transfer Time  : 0.001 sec
    Total Time     : 0.009 sec

However if am to call the procedure from Java, using the following code:

    public void testStoredProcedureInsert() throws SQLException{
    	SQLStatementBinder sqlBinder = new SQLStatementBinder();
    	sqlBinder.appendSql("CALL testInsert(?)");
    	sqlBinder.addBindVariable(0);
    	
    	Connection connection = new MysqlConnector("jdbc:mysql://localhost/dbname", "user", "pass").getConnection();
    	
    	CallableStatement stmt = connection.prepareCall(sqlBinder.getSQL());
    	
    	stmt = (CallableStatement)sqlBinder.bindSql(stmt);
    	
    	long start = System.currentTimeMillis();
    	
    	stmt.executeQuery();
    	
    	long end = System.currentTimeMillis();
    	
    	System.out.println("time to call procedure - " + (end-start) + "ms");
    }

The runtime of the update (note that I am only timing the actual execution so connection overhead and etc are not being taken into account) averages to be about <b>70ms</b>.

To even further illustration the point, if I put several inserts in a row into the stored procedure:

    DELIMITER $$
        
    CREATE PROCEDURE testInsert(IN input INT)
    BEGIN
    		INSERT INTO test_table(column_1, column_2) 
    		VALUES(input, input);

    		INSERT INTO test_table(column_1, column_2) 
    		VALUES(input, input);

    		INSERT INTO test_table(column_1, column_2) 
    		VALUES(input, input);

    		INSERT INTO test_table(column_1, column_2) 
    		VALUES(input, input);

    		INSERT INTO test_table(column_1, column_2) 
    		VALUES(input, input);
    		
        END$$
    
    DELIMITER ;

Calling from SQLyog still quite quick:
    
    Execution Time : 0.040 sec
    Transfer Time  : 0.003 sec
    Total Time     : 0.044 sec
    ---------------------------------------------------

Calling the same java code above now averages <b>210ms</b> per procedure call.

I am hoping that there is some trivial thing I am doing wrong, but am open to any suggestions or things that I should test. Or is there just that much extra overhead when calling from java?

Sorry for the somewhat long post but I was trying to provide a decent amount of information. Thanks for any help!