title: How to propagate MySQL exceptions to Java program?
body: <p>I have a java program that is calling a MySQL stored procedure that is rolled back when it gets an <code>SQLEXCEPTION</code>.  When I added the rollback (exit handler) to the stored procedure the Java program stopped getting the SQL exception.</p>
  
  <p>How can I make sure the SQL exception and MySQL error message are propagated back to the Java program?</p>
  
  <p>Here is my store procedure:  </p>
  
  <pre><code>DELIMITER $$
  
  DROP PROCEDURE IF EXISTS up_OMS_insertParticipantOmsOrderOwner $$
  CREATE PROCEDURE up_OMS_insertParticipantOmsOrderOwner(
                   IN PID int,
                   IN OwnerName varchar(50),
                   IN DisplayName varchar(50),
                   IN Enabled tinyint(1))
  
  BEGIN
  declare exit handler for SQLException
    BEGIN
      rollback;
    END;
  start transaction;
  
  if (DisplayName&lt;&gt;'') then
    insert OmsOrderOwner (ParticipantID, OmsOrderOwnerName, DisplayName, Enabled)
    value (PID, OwnerName,DisplayName, Enabled);
  else
    insert OmsOrderOwner(ParticipantID, OmsOrderOwnerName, DisplayName, Enabled)
    value (PID, OwnerName,null, Enabled);
  end if;
  
  set @OwnerID := @@identity;
  
  insert UserOmsOrderOwnerSubscription (UserID, ParticipantID, OmsOrderOwnerID, Enabled)
  select
    userOrderSub.UserId, PID, @OwnerID, 1
  from
    Users u,
    UserOmsOrderSubscription userOrderSub
  where
    userOrderSub.UserID = u.UserID and
    u.ParticipantID = PID;
  
  commit;
  
  END $$
  
  DELIMITER ;
  </code></pre>