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的账号和密码都正确。求解决方案!!在线等。急急急!!!!
看错误的描述肯定是程序链接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客户端工具测试帐号链接是否正常。
- 等 最代码怎么获取牛币啊?
- 完 谁来告诉我最代码上线的时间,答对者给5牛币,先来先得
- 等 牛友们,大家好,你们做程序员多久了?现在还好吗?
- 完 在微信打开的页面里进行app下载
- 等 最代码2014年欢乐聚声会
- 完 mysql如何查询表数据并且对3个字段降序的SQL?
- 完 最代码牛币机制改革
- 完 成功的在bae上使用了自定义运行环境 jetty+nginx的组合,大家对jetty+nginx优化有哪些心得?
- 完 进来分享一下各位牛牛是如何加入最代码大家庭的?
- 等 为什么java BufferedImage类处理大图直接抛出内存溢出的异常?
- 等 最代码是否开发手机app客户端?
- 完 java程序员学习哪些java的技术?java有哪些框架?都能做哪方面的开发?
- 等 php格式网页文件怎么运行?
- 等 Java volatile值获取的问题
- 等 前端vue,拦截了登录后台后,返回的token,requests拦截token,但是发送请求的时候,就出现跨越异常
- 等 大专本科计算机科班怎么找到Java工作?
- 等 eclipse怎么把三个java swing游戏项目合成一个项目?
- 完 伙伴们,大家都有什么好的解压方式么,分享一下~
- 完 三四线城市,6、7k,运维工作,索然无味,想去辞职上培训,各位牛牛有什么建议嘛
- 等 jsp页面输入中文变成问号
- 等 JPA在线上运行一段时间后报错Caused by: java.lang.IncompatibleClassChangeError: null
- 等 PHP 这个规则用preg_match_all怎么写
- 等 大佬们,有没有知道Alfresco如何配置LDAP登录呢?
- 等 php的install目录是框架带的吗?
- 等 javaWeb开源的聊天工具有那些?
- 完 java web如何实现中英文国际化?
- 完 java web的开发过程中,用到多线程的场景有哪些?
- 等 java web开发用什么语言的文件写页面啊,除了jsp格式的文件和html格式的文件?
- 等 如何学习java web开发?
- 等 javaWEB初学者如何学习?在学习路线上和方法上,或者资料的推荐?
- 完 java web现在流行的OA框架使用哪个?
- 等 java web项目启动欢迎页为什么没有样式返回404?
- 等 域名访问项目session为空,通过ip访问正常
- 等 java web运行程序后台为什么老报这个错误?Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them
- 等 java web在启动项目是报错 Error creating bean with name 'shiroFilter' defined in file
- 等 有无比较好的java web框架啦,例如jeesite、jty这样的开源项目源码?