NullPointerException error when using sql query to assign variable