Search code examples
mysqldatabasejspnetbeans

MySQL Access denied for user 'User'@'localhost' (using password: YES)


I connected a MySQL database for a project (java web application) in netbeans. I created MySQL server with correct login details as root and created a database. I connected my database to the project, but when I am running the application it was showing error in the browser as:

type Exception report

message Internal Server Error

description The server encountered an internal error that prevented it from fulfilling this request.

exception

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

root cause

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

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1.1 logs. 

Entry in the log file is:


java.sql.SQLException: Access denied for user 'User'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:925)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1704)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1250)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2465)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2498)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2283)
    at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:822)
    at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:404)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:317)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at org.apache.jsp.Login_jsp.cn(Login_jsp.java:114)
    at org.apache.jsp.Login_jsp._jspService(Login_jsp.java:589)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) 

I am tired in few ways as mentioned in some other forms but not use.


Solution

  • I found solution, When I was using sql statement for grant privileges i used

    'user@%'
    because of that it was not working. Correct sql statement was:
    GRANT ALL PRIVILEGES ON dbname.* TO 'User'@'localhost' IDENTIFIED BY 'Pass' WITH GRANT OPTION;