Handle SQL exceptions

  Updated