basic sql query and error handling