Spring的JdbcTemplate在查询超时后关闭连接吗? [英] Does Spring's JdbcTemplate close the connection after query timeout?

查看:3859
本文介绍了Spring的JdbcTemplate在查询超时后关闭连接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在set语句的方法中设置了查询超时(getJdbcTemplate()。setQueryTimeout(5))。查询超时后会发生什么,jdbc模板是否关闭我的连接?

I have set query timeout (getJdbcTemplate().setQueryTimeout(5)) in method with insert statement. What will happen after query timeout, does jdbc template close my connection?

推荐答案

长的答案取决于。

当您没有Spring管理事务时,则 JdbcTemplate 会调用 Connection 上的close()方法。但是,如果由于Springs事务管理已经有可用的连接,则连接将由Springs事务支持处理,这又会在上调用 close() c $ c>连接

When you don't have a Spring managed transaction then yes the JdbcTemplate will call the close() method on the Connection. However if there was already a connection available due to Springs transaction management closing the connection will be handled by Springs transaction support, which in turn also will call close() on the Connection.

唯一的区别是当连接关闭但 close()将被调用。

The only difference is when the connection is closed but close() will be called.

如果连接将被实际关闭取决于使用了 DataSource ,一般来说,当使用连接池时,连接将返回到而不是实际关闭连接。

If the connection will be actually closed depends on which DataSource is used, in general when using a connection pool the connection will be returned to the pool instead of actually closing the connection.

这篇关于Spring的JdbcTemplate在查询超时后关闭连接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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