Generally, this error means either the query has issues or the connection. Make sure you add and remove the semi-colon at the end of your query and see if that is the issue.
Otherwise, let's try to build a step by step troubleshooting procedure:
I) Make sure the connection object created is fine.
1. Make sure there are no params and/or templates. Basically hardcode URL, username, and password
2. Use a very simple query like "Select count(*) from table_name.
3. Use the connection and this query in one step.
II) Parameterize your connection if required and test it with the same above query.
III) Once you make sure the connection is ok, try to use another query that is a bit more sophisticated.
IV) Use your query (for your test) without any parameters first with the above connection and make sure it works.