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