Remote database connection open for long time

半腔热情 提交于 2019-12-11 11:09:09

问题


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 */}
    }
}

回答1:


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.



来源:https://stackoverflow.com/questions/11038836/remote-database-connection-open-for-long-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!