changed some Exception handling for SQL