Results 1 to 4 of 4
  1. #1
    sharanya is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default SQLException caught: Access denied for user 'root'@'localhost' (using password: YES)

    hi i developed a registraion form using jsp
    the code is as follows


    <body bgcolor="#999966">

    <form action="/userregister/Registration" method=post>

    <table cellpadding=4 cellspacing=2 border=0>

    <th bgcolor="#999966" colspan=2>

    <font size=5>REGISTRATION</font>

    <br><font size=1><sup></sup></font><hr>

    </th><tr bgcolor="#999966"><td valign=top>

    <b>First Name<sup>*</sup></b>

    <br><input type="text" name="firstname" value="" size=15 maxlength=20>

    </td><td valign=top><b>Last Name<sup>*</sup></b>

    <br><input type="text" name="surname" value="" size=15 maxlength=20></td>

    </tr><tr bgcolor="#999966">

    <td valign=top><b>E-Mail<sup>*</sup></b>

    <br><input type="text" name="email" value="" size=25

    maxlength=125><br></td><td valign=top>

    <b>Zip Code<sup>*</sup></b> <br>

    <input type="text" name="zipcode" value="" size=5 maxlength=6></td>

    </tr><tr bgcolor="#999966"><td valign=top colspan=2>

    <b>User Name<sup>*</sup></b><br>

    <input type="text" name="userId" size=10 value="" maxlength=10>

    </td></tr><tr bgcolor="#999966">

    <td valign=top><b>Password<sup>*</sup></b>

    <br><input type="password" name="address1" size=10 value=""

    maxlength=10></td><td valign=top>

    <b>Confirm Password<sup>*</sup></b>

    <br><input type="password" name="address2" size=10 value=""


    </tr><td valign=top>


    <br><input type="text" name="town" size=10 value=""


    <br></tr><td valign=top>


    <br><input type="text" name="country" size=10 value=""


    </tr><tr bgcolor="#663300">

    <td align=center colspan=2><hr>

    <input type="submit" value="Submit"></td></tr></table></center></form>



    and the servlet is

    package myservlets;


    import java.sql.*;

    import javax.servlet.*;

    import javax.servlet.http.*;

    public class Registration extends HttpServlet{

    public void init(ServletConfig config) throws ServletException{



    public void doPost(HttpServletRequest req, HttpServletResponse res)

    throws ServletException, IOException{

    String connectionURL = "jdbc:mysql://localhost/jsp";

    Connection connection=null;

    ResultSet rs;


    PrintWriter out = res.getWriter();

    String uId = req.getParameter("userId");

    String fname = req.getParameter("firstname");

    String sname = req.getParameter("surname");

    String address1 = req.getParameter("address1");

    String address2 = req.getParameter("address2");

    String town = req.getParameter("town");

    String county = req.getParameter("country");

    String zipcode = req.getParameter("zipcode");

    try {


    connection = DriverManager.getConnection(connectionURL, "root", "notallowed");

    String sql = "insert into emp_details values (?,?,?,?,?,?,?,?)";

    PreparedStatement pst = connection.prepareStatement(sql);

    pst.setString(1, uId);

    pst.setString(2, fname);

    pst.setString(3, sname);

    pst.setString(4, address1);

    pst.setString(5, address2);

    pst.setString(6, town);

    pst.setString(7, county);

    pst.setString(8, zipcode);

    int numRowsChanged = pst.executeUpdate();

    out.println(" Welcome : ");

    out.println(" '"+fname+"'");



    catch(ClassNotFoundException e){

    out.println("Couldn't load database driver: " + e.getMessage());


    catch(SQLException e){

    out.println("SQLException caught: " + e.getMessage());


    catch (Exception e){



    finally {

    try {

    if (connection != null)



    catch (SQLException ignored){






    when i run this am getting the errror as

    SQLException caught: Access denied for user 'root'@'localhost' (using password: YES)

    please can any one say actually what is the problem

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    You need to use code tags.

    Also you need to tell us what db you're using.
    I can guess, but I shouldn't have to.

  3. #3
    sharanya is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default SQLException caught: Access denied for user 'root'@'localhost' (using password: YES)

    hi u can see in my code am trying to connect to mysql database

    and use said use code tags

    sorry i dont have any idea regarding that
    can u sen any sample application

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power


    Java Code:
    This is in code tags.
    They mean the formatting of your code is maintained and we can actually read it.
    Unformatted code is very difficult to read.

    You need to provide us with as much information as possible to answer your question. Expecting us to read your (unformatted) code to see which db you were connecting to is likely to result in people simply not bothering.

    The answer is that you haven't given user root@localhost permission to access your database.

Similar Threads

  1. Jni registry 'access denied' error.
    By durino13 in forum Advanced Java
    Replies: 4
    Last Post: 09-17-2011, 08:06 AM
  2. Replies: 22
    Last Post: 04-09-2011, 05:59 AM
  3. Access is denied
    By tholland in forum New To Java
    Replies: 2
    Last Post: 12-20-2010, 09:57 PM
  4. access denied
    By Dennis in forum Advanced Java
    Replies: 8
    Last Post: 06-05-2010, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts