1
votes

I am using Wampserver. I am currently programming in jsp,but it gives me an error: Access denied for user 'root'@'localhost' (using password: YES)

My Code is :

    <%@ page import ="java.sql.*" %>
    <%
    try{
    String user = request.getParameter("uname");    
    String pwd = request.getParameter("pass");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String email = request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/quiz",
        "root", " ");
Statement st = con.createStatement();
//ResultSet rs;
int i = st.executeUpdate("insert into members(first_name, last_name, email, uname, pass, regdate) values ('" + fname + "','" + lname + "','" + email + "','" + user + "','" + pwd + "', CURDATE())");
if (i > 0) {
    //session.setAttribute("userid", user);
    response.sendRedirect("welcome.jsp");
   // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to       Login</a>");
} else {
    response.sendRedirect("index.jsp");
}
}
 catch(Exception e)
 {
  out.print(e.getMessage());
 }
 %>
1

1 Answers

0
votes

you should put the correct password and not (" ") or create new user in wampServer

like this :

'

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

FLUSH PRIVILEGES;

'

and your code will be :

    <%@ page import ="java.sql.*" %>
    <%
    try{
    String user = request.getParameter("uname");    
    String pwd = request.getParameter("pass");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String email = request.getParameter("email");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/quiz",
        "user", "password");
Statement st = con.createStatement();
//ResultSet rs;
int i = st.executeUpdate("insert into members(first_name, last_name, email, uname, pass, regdate) values ('" + fname + "','" + lname + "','" + email + "','" + user + "','" + pwd + "', CURDATE())");
if (i > 0) {
    //session.setAttribute("userid", user);
    response.sendRedirect("welcome.jsp");
   // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to       Login</a>");
} else {
    response.sendRedirect("index.jsp");
}
}
 catch(Exception e)
 {
  out.print(e.getMessage());
 }
 %>