事情起因:用Mac提交云笔记项目到SVN后,使用台式机import SVN上的云笔记代码,发现到了台式机上,进行junit测试时无法连接Mysql数据库服务器,而Mac上是可以的。以下是报警内容和报警画面

测试连接失败画面:

报警内容:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
### The error may exist in file [F:\workspace\Cloud_Note_Clyang\target\classes\Mapper\NoteMapper.xml]
### The error may involve com.boe.Dao.NoteDAO.findNoteByNoteBookId
### The error occurred while executing a query
### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
at com.sun.proxy.$Proxy19.selectList(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:230)
at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:128)
at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:68)
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:53)
at com.sun.proxy.$Proxy22.findNoteByNoteBookId(Unknown Source)
at Test.testNoteDAO.test(testNoteDAO.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
以下略...

分析解决:

通过报警内容,发现报“org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection”,“Cannot create PoolableConnectionFactory (Could not create connection to database server.)“

(1)发现报警不能连接MySQL服务器,网上也有类似的问题,他们是通过修改mysql数据库里user表的方法,参考博客 https://blog.csdn.net/qq_41675973/article/details/84898061

修改mysql库的user表,将host项,从localhost改为%。%这里表示的是允许任意host访问,如果只允许某一个ip访问,则可改为相应的ip,比如可以将localhost改为192.168.1.123,这表示只允许局域网的192.168.1.123这个ip远程访问mysql。
mysql> use mysql;
mysql> update user set host = ‘%’ where user = ‘root’;
mysql> select host, user from user;
mysql> flush privileges;
(2)另外一种是Mysql连接驱动包的问题

通过对比发现,Mac上Mysql的版本为5.7,驱动版本5.1.34,而台式机上Mysql的版本为8.0,驱动也为5.1.34,尝试将驱动从5.1.34更新为最新的5.1.46

    <dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>

更新后的驱动

重新进行测试连接:

发现可以通过笔记ID来查找到笔记Body内容,测试OK,原因为更换电脑后,Mysql版本更换,驱动包也需要随着更换。

云笔记项目-测试时无法连接MySQL Server的更多相关文章

  1. ems lite 客户端远程连接mysql server

    在本地用ems客户端远程连接虚拟机上的mysql server,弹出客户端没有权限访问mysql server.使用下面方法进行设置:mysql> select host,user,passwo ...

  2. 使用什么工具连接MySQL Server

    字符界面:命令行终端(需MySQL Client) GUI界面:Navicat.MySQL Workbench 开发语言:使用相应语言的MySQL数据库驱动包或模块连接MySQL 我一般用的是命令行, ...

  3. Java通过mysql-connector-java-8.0.11连接MySQL Server 8.0遇到的几个问题

    这次新安装了一个MySQL数据库,然后navicat连接数据库一点问题没有. 但是通过Java的jdbc连接却怎么都建立不了连接. 报如下错: 网上找了很久找到了原因: 数据库用的是Mysql8版本, ...

  4. VS2017项目中使用代码连接MySQL数据库,以及进行数据添加

    //头文件 #include "mysql.h" //函数定义 // 执行sql语句, 包括增加.删除.更新数据 bool ExecuteSql(MYSQL m_mysql,con ...

  5. Android真机测试时无法连接服务器

    之前服务器的通信一直是在模拟机上实现的,今天用在真机上却不成功.百度之后发现是安卓9以后禁止使用HTTP直接访问服务器.记录一下以后使用. 参考博文:https://blog.csdn.net/don ...

  6. 数据库导入时出现“2006 - MySQL server has gone away”问题的解决(windows)

    1.查到文件my.ini,在文件最后([mysqld]段最后),修改"max_allowed_packet = 50M",添加"interactive_timeout = ...

  7. 用msi安装MySQL时MySQL Server组件不能安装,或安装失败

    我的环境:       MySQL8.0.15,       win10 错误描述:在安装MySQL时,如果MySQL Server组件提示不能安装,错误提示是:VS 2015没有安装或安装失败.原因 ...

  8. 用EntityFramework6连接MySQL【转】

    http://www.cnblogs.com/wujingtao/p/5399950.html 不是微软的亲儿子这待遇就是不一样,其中的坑可真实不少,第一次连MySQL足足折腾了我大半天. 废话不多说 ...

  9. 使用EntityFramework6连接MySQL

    使用EntityFramework6连接MySQL 不是微软的亲儿子这待遇就是不一样,其中的坑可真实不少,第一次连MySQL足足折腾了我大半天. 废话不多说直接开始. 安装MySQL 从官网上下载最新 ...

随机推荐

  1. StanFord ML 笔记 第十部分

    第十部分: 1.PCA降维 2.LDA 注释:一直看理论感觉坚持不了,现在进行<机器学习实战>的边写代码边看理论

  2. 2690036 - SAP HANA 2.0 SPS 03 Database Revision 034

    Symptom This is the SAP Release Note for SAP HANA 2.0 Database Revision 034 (2.00.034.00) of the SAP ...

  3. 16.纯 CSS 创作一个渐变色动画边框

    原文地址:https://segmentfault.com/a/1190000014785816 感想:边框是伪元素::after来的: HTML代码: <div class="box ...

  4. 开源 人脸识别 openface 实用介绍 实例演示 训练自己的模型

    1.OpenFace 是 卡耐基梅陇(CMU)大学的一个图像+机器学习项目,整体程序包含:人脸发现,特征提取,特征神经网络训练,人脸识别这四部分. github   https://github.co ...

  5. GitHub使用指南之快速入门

    出自http://blog.csdn.net/column/details/13170.html 1.Git安装 Git是一个版本控制系统,使用之前必须先下载安装,下面提供各平台的安装方式. Mac: ...

  6. ssm学习的第一个demo---crm(1)

    这是一个普通的CRM项目 (第一步规划好项目设计路线:导入jar包→配置sqlMapConfig.xml(空文件)→配置applicationContext.xml →配置springMVC.xml→ ...

  7. 白鹭引擎 - 事件机制 ( Event, addEventListener, dispatchEvent )

    1, 自定义事件, MyEvent class MyEvent extends egret.Event { /** * 一般会定义一个 DATA 字段作为事件 * 绑定事件监听器时, 一般用 类.DA ...

  8. div产生的滚动条返回顶部

    div产生的滚动条返回顶部 1.获取div js: let initialNode = document.getElementById("content") react: let ...

  9. USB之HID类Set_Report Request[调试手记1]

    请翻开<Device Class Definition for Human Interface Devices (HID) Version 1.11 >7.2.2 Set_Report R ...

  10. 机器学习进阶-直方图与傅里叶变换-傅里叶变换(高低通滤波) 1.cv2.dft(进行傅里叶变化) 2.np.fft.fftshift(将低频移动到图像的中心) 3.cv2.magnitude(计算矩阵的加和平方根) 4.np.fft.ifftshift(将低频和高频移动到原来位置) 5.cv2.idft(傅里叶逆变换)

    1. cv2.dft(img, cv2.DFT_COMPLEX_OUTPUT) 进行傅里叶变化 参数说明: img表示输入的图片, cv2.DFT_COMPLEX_OUTPUT表示进行傅里叶变化的方法 ...