Hey Chris,

You have a line in your link that reads:

    // if you want to issue multiple queries and/or
    // work with multiple result sets, either declare more Statement
    // and ResultSet locals above and duplicate all cleanup logic for them,
    // or make sure you close each object along the way before you
    // try to re-use the reference

I have the following code in one of my data accessing methods:

        [same ps and rs instantiating as you]

        try {
        ps = connection.prepareStatement(query1);
        rs = ps.executeQuery();

        ...[process rs. (I dont close the ps or the rs at this point)]

        ps = connection.prepareStatement(query2);
        rs = ps.executeQuery();
        ....
        }

        [catch and finally blocks as you specify]

As you can see I simply reuse the ps and rs variables, without closing them
beforehand. Is this a problem?
The reason this never raised a flag before is because I have another
database accessing method that executes two queries in the same fashion and
it never caused any issues.

Thanks a lot.
_


On Fri, Sep 16, 2016 at 7:18 PM, Yuval Schwartz <yuval.schwa...@gmail.com>
wrote:

> Thanks Chris, I'll have a look.
>
> On Fri, Sep 16, 2016 at 6:41 PM, Christopher Schultz <
> ch...@christopherschultz.net> wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA256
>>
>> Yuval,
>>
>> On 9/16/16 3:32 AM, Yuval Schwartz wrote:
>> > A few more words/questions on my issue:
>> >
>> > My Resource element used the attribute "removeAbandoned" rather
>> > than "removeAbandonedOnBorrow". I have now corrected this. Does
>> > this affect what gets logged (ie: I've had "logAbandoned" on this
>> > whole time but have not seen anything in the logs about abandoned
>> > connections, is it possible that I will now see information about
>> > abandoned threads in my logs)?
>> >
>> > "removeAbandonedOnBorrow" doesn't really solve my issue since it
>> > doesn't get to the core of the problem, how will I know to
>> > recognize when an abandoned connection has been removed so that I
>> > can correct the bad code in my application.
>>
>> My bet is on a code path that simply fails to return a connection, or
>> a code path that requests two connections and therefore deadlocks when
>> things get busy.
>>
>> Have a look at this:
>> http://blog.christopherschultz.net/index.php/2009/03/16/properly-handlin
>> g-pooled-jdbc-connections/
>> <http://blog.christopherschultz.net/index.php/2009/03/16/properly-handling-pooled-jdbc-connections/>
>>
>> It might help you track down what's going on.
>>
>> Hope that helps,
>> - -chris
>> -----BEGIN PGP SIGNATURE-----
>> Comment: GPGTools - http://gpgtools.org
>> Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
>>
>> iQIcBAEBCAAGBQJX3BKlAAoJEBzwKT+lPKRY3RoP/AxYmD6buD7kkQF0DTWLjDa2
>> dmJSVqAj4mtxDoIeRfbMmNAUz7Y4kVq7AmHj3coPKMukk8CU4676IYgKjqXCtB7K
>> a91cR/yC5FKlGuZwIxtG1oqIUQDvg5e5j2k1hX918nFdNMjJLLoF+7xNkNauKi3/
>> rafsVD12GI34jXZLxna2gfFO6kkLAjXkHSyTU9p2+6gIzHcTd6hqAsVlqkCPGDGT
>> ODcC2nFWxqLx+snTdJRuGiU/LVxNPDBObqqKWZ3CKQQaWIQ0a7aHXe7bGq3aWsBA
>> GJHMtWpLpwyB9dpRzbTXE/Phj+WkvifUDTVtBSin1YkrQcLhaAqwViszRKl2wXnd
>> wtwYXiYo86QsHwfXLeq1GDfH0FmnGphdpVYe0J6nnSxgNb7kSTaX+FPkOaqKQD0g
>> phs41jcMipgFyOrdDVPbt2ntHOoP3VmFUqNmHnhdqOJx0xI+gQKglB4NAY/BQGvt
>> /yRdmHx3AGVLIp7nNGNKSrUK7vy/j6tynGYYMizRlnpOSZISbmVpAeDqjn5/Q27S
>> VYSPwA8UdrmB9tKAgSpXQMirTzt+PRVVD+zna4Dbe/thDyNbP/sNQn14nskCgf9y
>> aRmhC6R1j3TkjS7rzd7LLhlw69agjWm8s0roj+AVxCOX63xpm6RgDmaOUkoG+IZS
>> BJa1vpRmY21wlq6IaW5g
>> =Qvhj
>> -----END PGP SIGNATURE-----
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
>

Reply via email to