jdbc连接数据库出错The driver has not received any packets from the server.

般若波羅蜜多 2019-04-16 08:40:57
我用Java连接数据库总是连接不成功,抛出的异常大概是The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.貌似是没有连接到服务器,下面有截图。
我添加的jar包步骤应该是对的,我的MySQL服务也应该是开着的,可以在navicat上编辑。
百度搜索一天也没弄好,请各位神仙指点迷津,我是新手,可用分不多,全部奉上,万分感谢~

...全文
10715 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
shine2282 2021-12-24
  • 打赏
  • 举报
回复 3

其实就是SSL的问题,加上useSSL=false就好了

清韵凌波 2022-03-30
  • 举报
回复 1
@shine2282 正解!
般若波羅蜜多 2019-04-16
  • 打赏
  • 举报
回复
经过一番曲折,终于在你们的帮助下解决了,谢谢各位~~
首先我重装了mysql,又抛出两个异常,一个是加载驱动抛出的提示:Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'.我将Class.forName("com.mysql.jdbc.Driver")修改成了Class.forName("com.mysql.cj.jdbc.Driver");,
另一个是:The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.我将url改成了String url ="jdbc:mysql://localhost:3306/abc?useUnicode = true&characterEncoding = utf-8&useSSL = false&serverTimezone = GMT";
931828653 2019-04-16
  • 打赏
  • 举报
回复
try { Class.forName("com.mysql.jdbc.Driver"); System.out.println ("数据库驱动加载成功!"); con = DriverManager.getConnection("jdbc:mysql://localhost:3306/StudentSystem","ms","123456"); System.out.println ("数据库连接成功!"); } catch (ClassNotFoundException e1) { System.out.println ("数据库驱动加载失败!"); }catch(SQLException e2){ System.out.println ("数据库连接失败!"); } return con; } 抛异常 看看 然后 在main方法 调用下
咦哟~~~ 2019-04-16
  • 打赏
  • 举报
回复
引用 1 楼 般若波羅蜜多 的回复:
并且我的数据库abc在navicat上创建过了,用户名密码都正确
https://blog.csdn.net/shiqidide/article/details/7642531 建议看看这个
  • 打赏
  • 举报
回复
这个异常是说驱动程序没有收到来自服务器的任何数据。其它没问题的话,你可以执行一些简单的sql语句试试会不会报错,参考这里 https://blog.csdn.net/qq_44238142/article/details/88605985
般若波羅蜜多 2019-04-16
  • 打赏
  • 举报
回复
并且我的数据库abc在navicat上创建过了,用户名密码都正确

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧