wangdddd的gravatar头像
wangdddd 2015-11-28 15:09:50

eclipse运行java web项目报错:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:946)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:885)
    at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3421)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1247)
    at com.mysql.jdbc.Connection.createNewIO(Connection.java:2775)
    at com.mysql.jdbc.Connection.<init>(Connection.java:1555)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:215)
    at MyBlog.util.DbOption.createConnection(DbOption.java:35)
    at MyBlog.util.DbOption.executeQuery(DbOption.java:72)
    at MyBlog.Dao.UserDao.FindPass(UserDao.java:54)
    at MyBlog.Controller.LoginServlet.isLogin(LoginServlet.java:54)
    at MyBlog.Controller.LoginServlet.doPost(LoginServlet.java:35)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at MyBlog.filter.ChangeEncodeFilter.doFilter(ChangeEncodeFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2466)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2455)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:744)
十一月 28, 2015 2:49:02 下午 org.apache.catalina.core.StandardWrapperValve invoke

 

MySQL的账号和密码都正确。求解决方案!!在线等。急急急!!!!

所有回答列表(4)
wangjsaad的gravatar头像
wangjsaad  LV2 2015年11月30日

是sql账号名或者密码错了。仔细检查一下是不是开启了中文。多个空格什么的

评论(0) 最佳答案
最代码官方的gravatar头像
最代码官方  LV168 2015年11月29日

看错误的描述肯定是程序链接mysql的帐号错误导致。

方法一:写个简单的main函数测试下是否能正常连接:

	public static Map<Long, Map<String, Object>> findEvents() {
		Map<Long, Map<String, Object>> map = new HashMap<Long, Map<String, Object>>();
		Connection conn = null;
		try {
			String userName = "用户名";
			String password = "密码";
                        String db="数据库名";
			String jdbcurl = "jdbc:mysql://localhost:3306/"+db+"?useUnicode=true&characterEncoding=utf-8";
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection(jdbcurl, userName, password);
			String sql = "select id,type,user_id from my_table";
			PreparedStatement pstmt = conn.prepareStatement(sql);
			ResultSet rs = pstmt.executeQuery();
			while (rs.next()) {
				Long id = rs.getLong("id");
				int type = rs.getInt("type");
				Long user_id = rs.getLong("user_id");
				Map<String, Object> _map = new HashMap<String, Object>();
				_map.put("type", type);
				_map.put("user_id", user_id);
				map.put(id, _map);
			}
			pstmt.close();
		} catch (Exception e) {
			System.err.println("Cannot connect to database server,Exception:"
					+ e.getMessage());
		} finally {
			if (conn != null) {
				try {
					conn.close();
					conn = null;
				} catch (Exception e) {
				}
			}
		}
		return map;

	}

方法二,通过mysql客户端工具测试帐号链接是否正常。

eclipse运行java web项目报错:java.sql.SQLException: Access denied for user

幼儿园保安队长的gravatar头像
幼儿园保安队长  LV7 2015年11月30日

用你的 navicate 给那个root帐户授个对应数据库的权限就好了。 

在你的Manager Users 里面。公司电脑,没有环境,你自己先找找吧,不行晚上帮你弄

活动的hi的gravatar头像
活动的hi  LV2 2017年1月11日

问题描述:用Toad for MySQL可以连接上远程的MySQL数据库,但是用程序连接远程MySQL却报错:Access denied for user 'root'@'localhost' (using password: NO)
jdbc配置文件配置完全正确
解决办法:找到tomcat安装目录下的work目录,删除catalina目录,然后删除已部署的web工程.重新部署就ok
eclipse运行java web项目报错:java.sql.SQLException: Access denied for user 这问题好奇怪哈

顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友