执行java类连接MySQL数据库时报错:
“Communication link failure, message from server: “Can’t get hostname for your address”
解决方法:
1.在开始菜单中搜索“服务”
2.找到MySQL服务:
3.右键并修改属性,如下图所示:
4.再次运行Java即可,如果提示:
“Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by。。。”
这是提示你需要指明是否进行SSL连接,解决方案是在数据库连接的URL后面加上参数:
数据库名称后加上 ?characterEncoding=utf8&useSSL=true 例如:
String url = “jdbc:mysql://localhost:3306/elearning?characterEncoding=utf8&useSSL=true”;