If you are  receiving error like this:

Call to undefined method JException::setQuery()

Check connection to your database (if it is different then Joomla!).

If everything is ok, then try something like it is described here.