Fixing null pointer and wrong sql type error.