java.sql.SQLException: Error while cleaning up the server resources 异常解决

问题描述:

 今天遇到执行一个jdbc hive  sql 时,报以下异常:

2021-02-04 12:05:01 [cn.getech.data.manager.utils.HiveJdbcUtil#closeConnection]-[138]-[Thread-50] java.sql.SQLException: Error while cleaning up the server resources
	at org.apache.hive.jdbc.HiveConnection.close(HiveConnection.java:641)
	at cn.getech.data.manager.utils.HiveJdbcUtil.closeConnection(HiveJdbcUtil.java:135)
	at cn.getech.data.manager.service.strategy.ManagerHiveTemplate.closeHiveUtil(ManagerHiveTemplate.java:108)
	at cn.getech.data.manager.service.strategy.ManagerHiveTemplate.getLong(ManagerHiveTemplate.java:135)
	at cn.getech.data.manager.service.strategy.ManagerHiveTemplate.getLongValue(ManagerHiveTemplate.java:50)
	at cn.getech.data.manager.service.strategy.impl.DataSourceHiveStrategy.getTableRowNum(DataSourceHiveStrategy.java:121)
	at cn.getech.data.manager.service.impl.DataQualityInfoServiceImpl.buildQualityReport(DataQualityInfoServiceImpl.java:166)
	at cn.getech.data.manager.service.impl.DataQualityInfoServiceImpl$$FastClassBySpringCGLIB$$df628659.invoke()
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:684)
	at cn.getech.data.manager.service.impl.DataQualityInfoServiceImpl$$EnhancerBySpringCGLIB$$98bf66b7.buildQualityReport()
	at cn.getech.data.manager.service.impl.BuildDataQalityReportServiceImpl.buildDataQalityReport(BuildDataQalityReportServiceImpl.java:51)
	at cn.getech.data.manager.task.DataQualityTask.buildDataQalityReport(DataQualityTask.java:27)
	at cn.getech.data.job.datamanager.DataManagerMoveJob.buildDataQalityReportHandler(DataManagerMoveJob.java:69)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

其实问题的本质就是,statment语句执行一个sql时,在指定的时间内没有获取到结果,然后报超时异常后,紧接着去关闭connection 连接,而导致的异常。

 

问题解决:

如果我们的sql执行时间比较久,则将statment语句的查询时间设置久一点,对应的代码如下:

 private void conn () {
        try {
            Class.forName(driverName);
            con = DriverManager.getConnection(url, user, pwd);
            stmt = con.createStatement();
            stmt.setQueryTimeout(1800);
        } catch (ClassNotFoundException e) {
            XxlJobLogger.log("ClassNotFoundException获取hive数据连接异常={}",e.getMessage());
        } catch (SQLException e){
            XxlJobLogger.log("获取hive数据连接异常");
        }
    }

其中stmt 为 java.sql.Statement 对象实例

watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3Bpbmd3ZWljaGVuZw==,size_16,color_FFFFFF,t_70

 

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

成伟平2022

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值