java.sql.SQLException:在eclipse中尝试连接数据库时,用户'root'@'localhost'(使用密码:YES)拒绝访问

时间:2012-08-08 17:11:56

标签: java mysql

我在我的电脑上安装了wamp服务器。我可以毫无错误地访问phpmyadmin。

但是当我尝试在eclipse中连接到数据库时,对于应用程序,错误显示出来:

  

java.sql.SQLException:用户'root'@'localhost'拒绝访问(使用密码:YES)       在com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)       在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)       在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)       在com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919)       在com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)       在com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244)       在com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)       在com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)       在com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)       在com.mysql.jdbc.ConnectionImpl。(ConnectionImpl.java:813)       在com.mysql.jdbc.JDBC4Connection。(JDBC4Connection.java:47)       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)       at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)       at java.lang.reflect.Constructor.newInstance(Unknown Source)       在com.mysql.jdbc.Util.handleNewInstance(Util.java:411)       在com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)       在com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)       at java.sql.DriverManager.getConnection(Unknown Source)       at java.sql.DriverManager.getConnection(Unknown Source)       在org.apache.jsp.data_jsp._jspService(data_jsp.java:74)       在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:722)       在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)       在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)       在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:722)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)       在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)       在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)       在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)       在org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)       在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)       在org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)       at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:585)       at org.apache.tomcat.util.net.JIoEndpoint $ SocketProcessor.run(JIoEndpoint.java:310)       at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(Unknown Source)       在java.lang.Thread.run(未知来源)

这是data.jsp文件:

    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="com.mysql.*" %>
<?xml version="1.0"?>
<train>
<%
    Connection connection = null;
    Statement statement = null;
    ResultSet result = null;

    try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/train", "root", "*****");
        out.println("connected to database");
    } catch(Exception e) {
        e.printStackTrace();
        out.println("error!!!!");
    }
%>
</train>

所有密码都是正确的,但我无法在网上找到任何可以帮助我解决此问题的信息。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:4)

尝试运行此命令,看看它是否有帮助。在火车上授予所有特权。*以root @ localhost身份识别'nezinasi';