Page 3 of 4
Re: Unclosed connections
Posted: Sat Oct 16, 2010 7:22 pm
by Starter
Naonah wrote:I tried this and got syntax error, lol. Only this construction I wrote as last works

Did you replace the whole passage with my version? Because it works fine for me. oO
Re: Unclosed connections
Posted: Sat Oct 16, 2010 10:49 pm
by Naonah
Starter wrote:
Did you replace the whole passage with my version? Because it works fine for me. oO
Anyway it is the same, you also closed
2 times the same connection

Re: Unclosed connections
Posted: Sat Oct 16, 2010 10:55 pm
by Starter
Naonah wrote:Starter wrote:
Did you replace the whole passage with my version? Because it works fine for me. oO
Anyway it is the same, you also closed
2 times the same connection

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")
Re: Unclosed connections
Posted: Sun Oct 17, 2010 11:29 am
by Naonah
ok, you are right

Re: Unclosed connections
Posted: Sun Oct 17, 2010 1:24 pm
by Stake
Why close a connection twice? It's enough for once.
Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)
Re: Unclosed connections
Posted: Sun Oct 17, 2010 1:44 pm
by Starter
Stake wrote:Why close a connection twice? It's enough for once.
Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)
The master solution?! Thx.

Re: Unclosed connections
Posted: Wed Oct 20, 2010 4:24 pm
by CrownXp
can upload the fixed file and close the thread, ill be soo fine xD
Re: Unclosed connections
Posted: Thu Oct 21, 2010 12:49 pm
by Naonah
Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)
You cant use "finally" in Python.
Re: Unclosed connections
Posted: Thu Oct 21, 2010 1:49 pm
by janiii
Re: Unclosed connections
Posted: Thu Oct 21, 2010 2:56 pm
by Stake
Naonah wrote:Code: Select all
try : ins.executeUpdate() finally : ins.close() L2Databasefactory.close(con)
You cant use "finally" in Python.
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.
Re: Unclosed connections
Posted: Fri Oct 22, 2010 5:11 pm
by Naonah
oops, sry

but I had syntax error when used "finally"
Stake 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.
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 this

Re: Unclosed connections
Posted: Sat Oct 23, 2010 2:43 pm
by Naonah
Here, you have a proof that clause
finally is not working in Python (maybe in other Python version). I have
Python 2.2.1
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)
...and here result:
Code: Select all
Traceback (innermost last): (no code object) at line 0SyntaxError: ('invalid syntax', ('__init__.py', 734, 25, '\t\t\tfinally : L2DatabaseFactory.close(con)'))
Thank you.
Best regards.
Re: Unclosed connections
Posted: Sat Oct 23, 2010 2:50 pm
by janiii
http://docs.python.org/reference/compou ... s.html#try
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.
Re: Unclosed connections
Posted: Sat Oct 23, 2010 3:03 pm
by Stake
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)
Re: Unclosed connections
Posted: Sat Oct 23, 2010 3:06 pm
by jurchiks
I think it's the other way around:
Code: Select all
try : ins.executeUpdate()finally : try : L2Databasefactory.close(con) except : pass
might be wrong though.