Some updates

updated db connectivity
Finally fixed SQL query