Did you replace the whole passage with my version? Because it works fine for me. oONaonah wrote:I tried this and got syntax error, lol. Only this construction I wrote as last works
Unclosed connections
Forum rules
READ NOW: L2j Forums Rules of Conduct
READ NOW: L2j Forums Rules of Conduct
-
- Posts: 484
- Joined: Sat Jan 23, 2010 4:42 pm
Re: Unclosed connections
I have promises to keep and miles to go before I sleep.
- Naonah
- Posts: 357
- Joined: Sun Apr 04, 2010 11:12 pm
Re: Unclosed connections
Anyway it is the same, you also closed 2 times the same connectionStarter wrote:
Did you replace the whole passage with my version? Because it works fine for me. oO

public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
-
- Posts: 484
- Joined: Sat Jan 23, 2010 4:42 pm
Re: Unclosed connections
Huh? Maybe im a too bloody newbie at python but imo the openend connection is only 1 time closed (as needed) and only if an exception happens then another try to close the connection happens again. (at least this way its done at several more parts in the script when it comes to "prepareStatement")Naonah wrote:Anyway it is the same, you also closed 2 times the same connectionStarter wrote:
Did you replace the whole passage with my version? Because it works fine for me. oO
I have promises to keep and miles to go before I sleep.
- Naonah
- Posts: 357
- Joined: Sun Apr 04, 2010 11:12 pm
Re: Unclosed connections
ok, you are right 

public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
- Stake
- Posts: 383
- Joined: Sun Mar 23, 2008 9:33 pm
- Location: Hungary
- Contact:
Re: Unclosed connections
Why close a connection twice? It's enough for once.
Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)
Last edited by Stake on Sun Oct 17, 2010 1:25 pm, edited 1 time in total.


-
- Posts: 484
- Joined: Sat Jan 23, 2010 4:42 pm
Re: Unclosed connections
The master solution?! Thx.Stake wrote:Why close a connection twice? It's enough for once.Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)

I have promises to keep and miles to go before I sleep.
-
- Posts: 8
- Joined: Thu Sep 23, 2010 3:33 pm
Re: Unclosed connections
can upload the fixed file and close the thread, ill be soo fine xD
- Naonah
- Posts: 357
- Joined: Sun Apr 04, 2010 11:12 pm
Re: Unclosed connections
Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)
public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
- janiii
- L2j Veteran
- Posts: 4269
- Joined: Wed May 28, 2008 3:15 pm
- Location: Slovakia
Re: Unclosed connections
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
- Stake
- Posts: 383
- Joined: Sun Mar 23, 2008 9:33 pm
- Location: Hungary
- Contact:
Re: Unclosed connections
Never put close functions in try clause, always put them in finally, because you know, try only runs until exception is thrown, so if ins.close() throws an exception, L2Databasefactory.close() will not execute. But this way, all should work well.Naonah wrote:You cant use "finally" in Python.Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)


- Naonah
- Posts: 357
- Joined: Sun Apr 04, 2010 11:12 pm
Re: Unclosed connections
oops, sryjaniii wrote:yes, you can use finally in python:
http://docs.python.org/tutorial/errors. ... up-actions


Thank you for your help. I just wrote this cuz after applying your codes I got syntax error (with "finally"). Anyway using your solution I fixed thisStake wrote: Never put close functions in try clause, always put them in finally, because you know, try only runs until exception is thrown, so if ins.close() throws an exception, L2Databasefactory.close() will not execute. But this way, all should work well.

public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
- Naonah
- Posts: 357
- Joined: Sun Apr 04, 2010 11:12 pm
Re: Unclosed connections
Here, you have a proof that clause finally is not working in Python (maybe in other Python version). I have Python 2.2.1
...and here result:
Thank you.
Best regards.
Code: Select all
if event == "delete" : con=L2DatabaseFactory.getInstance().getConnection() rem=con.prepareStatement("DELETE FROM buffer_scheme_list WHERE id=? LIMIT 1") rem.setString(1, eventParam1) try : rem.executeUpdate() except : pass rem=con.prepareStatement("DELETE FROM buffer_scheme_contents WHERE scheme_id=?") rem.setString(1, eventParam1) try : rem.executeUpdate() rem.close() except : pass finally : L2DatabaseFactory.close(con) return rebuildMainHtml(st)
Code: Select all
Traceback (innermost last): (no code object) at line 0SyntaxError: ('invalid syntax', ('__init__.py', 734, 25, '\t\t\tfinally : L2DatabaseFactory.close(con)'))
Best regards.
public void l2jserver ()
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
{
if (you want l2j server == no problems)
use Linux;
else
use Windows;
}
- janiii
- L2j Veteran
- Posts: 4269
- Joined: Wed May 28, 2008 3:15 pm
- Location: Slovakia
Re: Unclosed connections
http://docs.python.org/reference/compou ... s.html#try
you dont need to write the except clause if you do only pass there. so you just have try and finally clause at the end, which works also for your python version.
Changed in version 2.5: In previous versions of Python, try...except...finally did not work. try...except had to be nested in try...finally.
you dont need to write the except clause if you do only pass there. so you just have try and finally clause at the end, which works also for your python version.
DO NOT EVEN TRY TO MESS WITH ME!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
forum flOOder dancing dEVILoper ♀
I don't give private support - PM will be ignored!
- Stake
- Posts: 383
- Joined: Sun Mar 23, 2008 9:33 pm
- Location: Hungary
- Contact:
Re: Unclosed connections
Or try the "nested" version.

Code: Select all
try : try : ins.executeUpdate() except : pass # unnecessary, but needed if you want to handle an exceptionfinally : ins.close() L2Databasefactory.close(con)


- jurchiks
- Posts: 6769
- Joined: Sat Sep 19, 2009 4:16 pm
- Location: Eastern Europe
Re: Unclosed connections
I think it's the other way around:
might be wrong though.
Code: Select all
try : ins.executeUpdate()finally : try : L2Databasefactory.close(con) except : pass
If you have problems, FIRST TRY SOLVING THEM YOURSELF, and if you get errors, TRY TO ANALYZE THEM, and ONLY if you can't help it, THEN ask here.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.
Otherwise you will never learn anything if all you do is copy-paste!
Discussion breeds innovation.