如果未在Java代码中关闭,则JDBC连接可以存活多长时间? [英] How long does a JDBC connection live if not closed in java code?

查看:144
本文介绍了如果未在Java代码中关闭,则JDBC连接可以存活多长时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在Java代码中打开JDBC连接却忘记关闭它,它将永远保持打开状态吗?还是我可以在某个地方指定默认的超时值?

If I open up a JDBC connection in my java code and forget to close it, will it remain open for ever? Or is there a default time out value that I can specify somewhere?

推荐答案

首先,您确实需要修复代码以将其关闭.没有任何借口.

In first place, you really need to fix the code to close it. No excuses.

关于具体问题,这取决于所使用的DB服务器.数据库服务器将超时并回收它.有关缺省值以及如何更改缺省值,请参阅特定于DB Server的管理手册.例如,对于MySQL,wait_timeout设置默认为28800秒(8小时).

As to the concrete question, that depends on the DB server used. It's the DB server who will timeout and reclaim it. Refer the DB server specific administration manual for defaults and how to change it. In case of for example MySQL, it's the wait_timeout setting which defaults to 28800 seconds (8 hours).

这篇关于如果未在Java代码中关闭,则JDBC连接可以存活多长时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆