I posted this message some time back, but dont know why nobody is answering it.It would be nice if somebody takes the time to help me out with this.I did look into the forums , but could not get a suitable error correction.
It would be great if someone helps me out in this very helpful forum.I am giving you the code I have so far written
Don't you need to provide an username and a password to connect to the database? Also, can you print out the sql statement, copy it and try to run it in some other utility to see if there is problem with the sql statement itself?
I can , I did a select * from <tablename> and it workds fine
Look at the permissions for the user you are connecting as - probably GUEST since you don't specify a username with your connection URL. Sounds like they only have permission to SELECT.
Also you might want to revise how you report the exception in your code - you have an error message "Unable to connect to DB" which will be logged when that is not the problem - you may well be able to connect, but you can't run the SQL. Generally trying to second guess what an exception will mean is not as good a strategy as just logging the stack trace and letting it tell you.