Why am I getting a syntax error when trying to create a stored procedure in MySQL? I would like to use a transaction to call upon a stored procedure on many rows. If it fails on a single row, I want to roll back everything. Otherwise I want to commit. 

I have the following so far but it throws the following error:


  You have an error in your SQL syntax; check the manual that
  corresponds to your MySQL server version for the right syntax to use
  near  'DECLARE val1 INT DEFAULT 0; DECLARE check INT DEFAULT 1;
  DECLARE done BOOL DEFAU' at line 3


 DELIMITER \\
 BEGIN

 DECLARE val1 INT DEFAULT 0;
 DECLARE check INT DEFAULT 1; 
 DECLARE done BOOL DEFAULT FALSE;
 DECLARE e INT DEFAULT 1;
 DECLARE cursor1 CURSOR FOR SELECT Table1.col1 FROM Table1 WHERE Table.col2 = (SELECT col1 FROM Table2 WHERE col3 = 'xxx');

 DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

 START TRANSACTION;

 OPEN cursor1;

 my_loop:
 LOOP

    FETCH NEXT FROM cursor1 INTO val1;
    IF done THEN
            LEAVE my_loop;
    ELSE
            storedProcedure1(val1,100,e);
            IF SELECT e = 0 THEN
                    ROLLBACK;
                    SET check = 0;
                    LEAVE my_loop;
            END IF;
    END IF;
  END LOOP;

  IF check = 1 THEN
       COMMIT;
  END IF;
  END;


Any ideas on what I may be doing wrong?
If you want to create a stored procedure, you have to use the CREATE PROCEDURE syntax, see the documentation. You can't use procedural language constructs such as DECLARE in normal SQL. 

Also, you have to use the special delimiter you've declared after the final END, so the last line will be END\\. (And after that, don't forget to set DELIMITER back to ;, or you'll struggle.)

(There could be other problems as well, these are just two I spotted right away.)