宝塔618特惠活动,企业版999元/年,宝塔SSL证书买1送1!限时抢购!查看活动
当前位置:论坛首页 > Linux面板 > 求助

navicat可连接服务端mysql,jdbc无法连接,求解决

发表在 Linux面板2021-5-5 14:52 [复制链接] 3 6798


相关代码:    private static String driver = "com.mysql.jdbc.Driver";

         private static String url = "jdbc:mysql://xxx.xxx.xx.xxx:3306/xxxxxx?useUnicode=true&characterEncoding=utf-8&useSSL=true";//MYSQL数据库连接Url
            private static String user = "xxxxxx";//用户名
            private static String password = "xxxxxx";//密码
            public static Connection getConn(){
                 Connection conn = null;
             try {
             Class.forName(driver);//获取MYSQL驱动
            Log.i("mysql   ","驱动加载成功");
            conn = (Connection) DriverManager.getConnection(url, user, password);//获取连接
            Log.i("mysql   ","数据库连接成功");


...
错误:CommunicationsException: Communications link failure



navicat可以访问,所以防火墙端口啥的应该是没问题的,但使用jdbc连接不上,不知道哪里出了问题,用户名和密码使用的是。
使用道具 举报 只看该作者 回复
发表于 2021-5-5 15:29:34 | 显示全部楼层
您好,参考下面文档做一下连接超时设置看看

https://blog.csdn.net/qq_23935173/article/details/110823341
使用道具 举报 回复 支持 反对
发表于 2021-5-5 16:58:16 | 显示全部楼层
谢花郎 发表于 2021-5-5 15:29
您好,参考下面文档做一下连接超时设置看看

https://blog.csdn.net/qq_23935173/article/details/11082334 ...

mysql> show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 604800   |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 604800   |+-----------------------------+----------+


已修改,但还是一样的错误。


使用道具 举报 回复 支持 反对
发表于 2022-5-20 14:35:53 | 显示全部楼层
请问解决了吗?
如何解决的?
使用道具 举报 回复 支持 反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

普通问题处理

论坛响应时间:72小时

问题处理方式:排队(仅解答)

工作时间:白班:9:00 - 18:00

紧急运维服务

响应时间:3分钟

问题处理方式:宝塔专家1对1服务

工作时间:工作日:9:00 - 18:30

宝塔专业团队为您解决服务器疑难问题

点击联系技术免费分析

工作时间:09:00至18:30

快速回复 返回顶部 返回列表