added a loop to SQL database

- returns error on sql syntax faulty.
- returns error when there's no sql query
  submitted.

Signed-off-by: Nicholas Tan Jerome <nicholas.jerome@kit.edu>