Added SQL exception handling.