File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Kindly help with the "cannot connect to the database" error

 
nash avin
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

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

/*** DatabaseConnection.java****/


/*** DatabaseConnection.java****/


Any help would be greatly appreciated.

Thanking you all in advance
AS
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the exact error message which is logged with the SQLException?
 
nash avin
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply.Sorry to have not included the error message .The error message I get is as follows



Thank you again for your time.

Help would be greatly appreciated.

AS
 
Craig Jackson
Ranch Hand
Posts: 405
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One suggestion, could it be that you don't have access to add records to this particular database?
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nash avin:





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?

Jayesh
 
nash avin
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Thanks a lot for the replies.I did print it out in a SQL utility and the statement is al right.

Regarding whether I can do the inserts, I can , I did a select * from <tablename> and it workds fine.

But Why is it with the insert....

It would be great if any one can direct me in the right direction.

Thanking you
AS
 
Jayesh Lalwani
Ranch Hand
Posts: 502
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest trying to run the exact same insert statement in the SQL utility using the same username/password
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nash avin:
I posted this message some time back


3 hours??? Isn't that a touch impatient?
Personaly I was asleep. I try to set aside some time for this every day.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic