updated retry condition, and wrapped the handling of  SQLExceptions