ses ses - 7 months ago 16
SQL Question

MySQL stored procedure returns false

After this method is invoked, the stored procedure is called (it puts 1000 new records to db). But bool is false, why?

public void loadTestData() throws SQLException {

CallableStatement cStmt = connection.prepareCall("{call loadTestData }");

boolean bool = cStmt.execute();

if (bool) System.out.println("test data is loaded");
else System.out.println("test data is not loaded!");
}





The Procedure is here:

CREATE DEFINER=`root`@`localhost` PROCEDURE `loadTestData`()
BEGIN

DECLARE x INT;

delete from user where id<5000;

SET x = 0;
WHILE x <= 100 DO
insert into user (name, description) VALUES(
concat("name", x),
concat("description", x)
);
SET x = x + 1;
END WHILE;

END

Answer

If your procedure's first result is not ResultSet the return value is false.

PreparedStatement.execute()