• Post Reply Bookmark Topic Watch Topic
  • New Topic

Access denied for user

 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys...

I am testing a piece of code to view a ceratin field from a table in the database. The code is as below.



When I run the program, I am getting the following error message in the browser:
-------------------------------------------------------------------------------------------------

Http Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
root cause

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

-------------------------------------------------------------------------------------------------------------------
Is the error message asking me to use password to make the connection? If so than I am puzzled. because I was playing around with Netbean's project woodstock and I was able to make the connection without the need for any password.

Even when I modified this line:


to this..



as in I have included the username and password and the problem still persists. This is very worrying, I really hope someone can help. Thanks..






 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is asking to log into the DB as user "root" with password "root" - does that account exist, and is the password correct? The error message ("Access denied for user 'root'") indicates that it is not.
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Appreciate the quick reply. The username is root and the password is appleorange. You mean the error is saying both the username and password is root?? I thoght the line:


would have taken care of things. If the above coding is wrong, what than is the correct way to indicate that username is root and password is apppleorange? Thanks.

 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A little hint: Look closely at how you get a Connection :-)
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd also seriously consider writing even "test" code like this in an actual Java class; there are many good reasons to do so.
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys...

Yes Ulf Dittmer you are right. The culprit is this line:


I have solved the problem by replacing the second root with my password. Thank you very much for pointing me in the right direction. I think I am no longer going to use this method of connection to the database from a jsp page. What I am going to try now is to get the jsp file to call a servlet, which will get a bean to extract the necessary data and pass it to the jsp file. I guess this will be in accordance to the MVC pattern. Another challenge is to kick start the process, by not clicking on the submit button in a form, but by something along the likes of an 'onload' fucntion, where when the browser loads, it loads with the table containing the data extracted from the table.

Hi David Newton, I read your posting, I am just curious were you actually trying to say 'seriously consider not writing' ?

Anyway thanks guys for the help.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I would never advocate writing code like that in a JSP. Re-read my post.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!