Results 1 to 8 of 8
Thread: Mutiple Connections problem
- 12-19-2011, 06:46 AM #1
Member
- Join Date
- Dec 2011
- Location
- Kathmandu, Nepal
- Posts
- 15
- Rep Power
- 0
Mutiple Connections problem
Hi I am having a problem with multiple connections opened though I have closed them using cn.close() method.
Actually, I have a frame contains multiple instances of panels containing the records on JLabel. I have setText() on labels from MySQL.
The query goes like this:
There are 15 panels in a frame.Java Code:public void fillDetails(int ID) { Connection cn = null; Statement stmt = null; ResultSet rss = null; try { cn = connectMySql.conn(); String sqltempCDR = "select amount from table1 where id=" + ID + ""; stmt = cn.createStatement(); rss = stmt.executeQuery(sqltempCDR); int li_row = 0; if (rss != null) { while (rss.next()) { amount = amount + rss.getDouble(1); li_row++; } } labelTotalAmountValue.setText(Double.toString(amount)); rss.close(); stmt.close(); cn.close(); } catch (Exception e) { e.PrintStackTrace(); } }
So when I load the application this method is invoked 15 times.
and though I have closed the connection, when i try to view the connection state in ms-dos command using netstat -a
it dispaly around 15-16 connections
with
proto local address foreign address State
tcp ip-address TIME_WAIT
and I think this is also the reason that my application consumes Mem usage alot too and becomes slow.
Any solution plz....
Thanks in advanceLast edited by Eranga; 12-19-2011 at 10:37 AM. Reason: code tags added
- 12-19-2011, 07:13 AM #2
Member
- Join Date
- Dec 2011
- Location
- Kathmandu, Nepal
- Posts
- 15
- Rep Power
- 0
Re: Mutiple Connections problem
I tried using the finally too
finally
{
if(cn!=null)
{
cn.close();
}
}
- 12-19-2011, 10:39 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Mutiple Connections problem
In a single execution of cycle, you have to open the connection then process data and then close the connection. You have to maintain the sequence in each cycle. Seems you don't have work on that.
- 12-19-2011, 10:40 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Mutiple Connections problem
And also please use the code tags when you are posting again. Unformatted codes are really hard to read.
- 12-19-2011, 10:47 AM #5
Member
- Join Date
- Dec 2011
- Location
- Kathmandu, Nepal
- Posts
- 15
- Rep Power
- 0
Re: Mutiple Connections problem
But I think this is the process you open connection, process, then close the connection. If you have better way plz suggest me.
- 12-19-2011, 10:49 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Re: Mutiple Connections problem
Only the other possibility you have is that open a connection and keep for the complete of all the processing you have. Connection open/close in periodically required lots of resources.
- 12-19-2011, 11:33 AM #7
Banned
- Join Date
- Dec 2011
- Posts
- 143
- Rep Power
- 0
Re: Mutiple Connections problem
TIME_WAIT is a TCP thing. It can hang around for a while after a connection is closed. Try again and wait a good few minutes to see if the TIME_WAITs disappear.
- 12-19-2011, 11:35 AM #8
Member
- Join Date
- Dec 2011
- Location
- Kathmandu, Nepal
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Problem with pool connections
By juamd in forum Advanced JavaReplies: 9Last Post: 06-02-2011, 06:32 PM -
mutiple object
By ahmed80 in forum New To JavaReplies: 1Last Post: 01-07-2011, 12:57 AM -
Storing Mutiple Classes/Data Types in a Linked List
By Chronoattica in forum New To JavaReplies: 7Last Post: 12-28-2010, 10:03 PM -
issue of mutiple panels
By de.megha in forum AWT / SwingReplies: 1Last Post: 07-26-2010, 09:27 AM -
Mutiple Selection without control key in Tree componet
By atmohsin in forum SWT / JFaceReplies: 0Last Post: 03-24-2010, 10:39 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks