正在回答 回答被采纳积分+1
9回答
芝芝兰兰
2019-08-18 15:41:48
同学你好,这里localhost接着的是3306不是8080的原因是mysql的端口号是3306。
“localhost”代表本地主机,就是同学手中的这台机器,而这些端口号就是用来区分同学电脑中那么多应用程序的一种机制。
我们之前访问localhost:8080是要访问Tomcat服务器,Tomcat的默认端口号是8080。
我们现在要访问的是mysql数据库,它的默认端口号是3306。
有关这个报错,老师在最新的问答 http://class.imooc.com/course/qadetail/145843 中回复你了哦~
祝学习愉快~
好帮手慕阿满
2019-08-18 10:02:39
同学你好,问一下同学的mysql是8的版本吗?如果是,需要将lib包下的mysql驱动换成8的版本。另外url链接有些问题,MySQL8的链接参考如下:
private static String url = "jdbc:mysql://localhost:3306/message_board?usessl=false&useUnicode=true&serverTimezone=GMT%2B8&characterEncoding=utf8"
另外需要建议同学将密码修改为自己MySQL的密码。
如果我的回答解决了你的疑惑,请采纳。祝:学习愉快~
讓倪飛翔
2019-08-17 19:38:32
package com.imooc.jdbc.common; import java.sql.*; /** * 数据库操作公共类 * * @version 1.0 */ public final class ConnectionUtil { private static String url = "jdbc:mysql://localhost:3306/message_board"; private static String user = "root"; private static String password = ""; private ConnectionUtil(){} static { try{ Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e){ System.out.println("找不到驱动程序类,加载驱动失败。"); e.printStackTrace(); } } /** * 获得数据库连接 * @return */ public static Connection getConnectio(){ try { return DriverManager.getConnection(url,user,password); } catch (SQLException e) { System.out.println("创建数据库连接失败。"); e.printStackTrace(); } return null; } /** * 释放数据库资源 * @param rs ResultSet * @param stmt Statement * @param connection Connection */ public static void release(ResultSet rs, Statement stmt, Connection connection){ try { if(rs != null){ rs.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if(stmt != null){ stmt.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if(connection != null){ connection.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { } } } } }
按照老师的步骤一个一个敲上去的,还一直报错,还让不让人活了???
讓倪飛翔
2019-08-17 19:28:58
这是所有的报错信息
[2019-08-17 07:24:25,516] Artifact JDBCMessageBoard:war exploded: Artifact is deployed successfully [2019-08-17 07:24:25,516] Artifact JDBCMessageBoard:war exploded: Deploy took 596 milliseconds com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Client does not support authentication protocol requested by server; consider upgrading MySQL client 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:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) at com.mysql.jdbc.Util.getInstance(Util.java:386) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1013) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3609) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:943) at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4113) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1308) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2336) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2369) at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2153) at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:792) at com.mysql.jdbc.JDBC4Connection.<init>(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:423) at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) 创建数据库连接失败。 at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:381) at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305) at java.sql.DriverManager.getConnection(DriverManager.java:664) at java.sql.DriverManager.getConnection(DriverManager.java:247) at com.imooc.jdbc.common.ConnectionUtil.getConnectio(ConnectionUtil.java:32) at com.imooc.jdbc.dao.MessageDAO.getMessages(MessageDAO.java:26) at com.imooc.jdbc.service.MessageService.getMessages(MessageService.java:27) at com.imooc.jdbc.servlet.MessageListServlet.service(MessageListServlet.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748) 17-Aug-2019 19:24:34.419 淇℃伅 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\apache-tomcat-8.5.38\webapps\manager] 17-Aug-2019 19:24:34.512 淇℃伅 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\apache-tomcat-8.5.38\webapps\manager] has finished in [93] ms
讓倪飛翔
2019-08-17 09:42:19
ConnectUtil.java
package com.imooc.jdbc.common; import java.sql.*; /** * 数据库操作公共类 * * @version 1.0 */ public final class ConnectionUtil { private static String url = "jdbc:mysql://localhost:3306/message_board"; private static String user = "root"; private static String password = ""; private ConnectionUtil(){} static { try{ Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e){ System.out.println("找不到驱动程序类,加载驱动失败。"); e.printStackTrace(); } } /** * 获得数据库连接 * @return */ public static Connection getConnectio(){ try { return DriverManager.getConnection(url,user,password); } catch (SQLException e) { System.out.println("创建数据库连接失败。"); e.printStackTrace(); } return null; } /** * 释放数据库资源 * @param rs ResultSet * @param stmt Statement * @param connection Connection */ public static void release(ResultSet rs, Statement stmt, Connection connection){ try { if(rs != null){ rs.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if(stmt != null){ stmt.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if(connection != null){ connection.close(); } } catch (SQLException e) { e.printStackTrace(); } finally { } } } } }
Java数据库开发与实战应用2018版
- 参与学习 人
- 提交作业 277 份
- 解答问题 4297 个
Java数据库开发的必备技能,从流行的MySQL数据库开始,到Java原生的数据库管理接口JDBC的使用,再到常用的数据持久化框架MyBatis,让你向Java工程师的目标又迈进了一步!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星