added mysql exception to handle errors gracefully