远程数据库连接打开很长时间 [英] Remote database connection open for long time

查看:239
本文介绍了远程数据库连接打开很长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过远程连接在mssql server 2008数据库上执行一些crud。我有Java中的业务逻辑,连接,语句和结果集close()在finally块中的严格代码。

我的疑问是,即使我完成作业,连接端口仍然打开, 20分钟关闭所有连接。我可以使用netstat -a命令查看打开的连接。

我需要快速关闭连接,因为每个操作打开/关闭连接几次。因此,我看到大量的连接打开。这是非常不安全和昂贵的保持这么多不需要的连接长时间,业务逻辑已经关闭。
我使用最新的jtds.jar文件。

谢谢,

Akshay

I am executing some crud's on mssql server 2008 database by connecting remotely. I have business logic in Java with tight code for connection, statement and result set close() in finally block.
My doubt is, even when I finish the job the connection port are still open and it takes roughly 20 min to close all connections. I can view the open connection using netstat -a command.
I need to quickly close the connections since each operation opens/close connection several times. Hence I see large number of connections open. This is very insecure and costly to keep so many unwanted connections for long time which the business logic has already closed. I am using the latest jtds.jar file. Any hint or suggestion will be appreciated.
Thanks,
Akshay

Connection conn = null;
PreparedStatement ps = null;

ResultSet rs = null;

try {
    // Do stuff
    ...

} catch (SQLException ex) {
    // Exception handling stuff
    ...
} finally {
    if (rs != null) {
        try {
            rs.close();
        } catch (SQLException e) { /* ignored */}
    }
    if (ps != null) {
        try {
            ps.close();
        } catch (SQLException e) { /* ignored */}
    }
    if (conn != null) {
        try {
            conn.close();
        } catch (SQLException e) { /* ignored */}
    }
}


推荐答案

对不起,谢谢你抽出时间回答我的问题。
连接关闭是一个框架调用,没有正确关闭。我没有访问它,所以我认为这不是问题。再次感谢您的时间和指导。

Sorry guys and Thanks for taking out time to answer my question. The connection close was a framework call which was not closing properly. I didn't had access to it so I thought that was not the issue. Thank you once again for your time and guidance.

这篇关于远程数据库连接打开很长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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