Hello Chris, On Sat, Sep 17, 2016 at 7:40 PM, Christopher Schultz < ch...@christopherschultz.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA256 > > Yuval, > > On 9/16/16 2:33 PM, Yuval Schwartz wrote: > > 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? > > That depends upon your database driver. I seem to recall Oracle > specifically being very unforgiving when it comes to failing to close > resources. I would add explicit "close" calls to every object you are > expecting to be finished with. > > > 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. > > Are there any other factors involved? Maybe that other accessing > method doesn't get called very often? Is it in a separate process > where cleanup happens when the process completes? Do you have some > other kind of pooling mechanism that will auto-close resources? > > I think it's always a good idea to follow the API's recommendations > about closing resources when you are done with them. In the worst > case, the close() method is a no-op and it will eventually be JIT'd > away. In the best case, you get clean resource management. > > Thanks, I found information about this in forums and made the change. I'll also look for it in formal documentation when I have some more time. Thanks for your help, this was most likely the issue. > - -chris > > -----BEGIN PGP SIGNATURE----- > Comment: GPGTools - http://gpgtools.org > Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ > > iQIcBAEBCAAGBQJX3XIPAAoJEBzwKT+lPKRYhKsQAJo/+GhhRAQ2y6Mqkr54Ufb5 > Wz22WHvJ15er8z/LdZ8FLzGchD7WsmgBZj8v3yeEptzoxK7rhjvoxrO7w6ZTtz7x > 6Qogj+qa+/HeUqELnr2SkQdyrMp+aal/DEXQvMvFp+VAKrEq+x0OKeMGBvzaimsf > xt9AWHeD5YsfRyGqvW/RFDIPFcSq83VDha2owQEcvvzNaw/DRTPTi/OubHoDuFtF > +MCkLjXRkbYThg/ljElWivEDd2NZJP5yDtwTBAsnQeydvKVpN7vzA47tQOznbxHN > eVhM1aPxQim1Jt3++jXT+ByGHNpiHLuhKkxwVPm8ZD6WyWgFGHp7R6w9eddnMLth > mUhzS5HPCLYOS0x3XcuheuhybEQdWNiBh4d6dQS59+rkdU3CASPWrbwFsdEPwMq1 > 0OdDJAZ436t+EP+XJjObnT8KV9wBWFzEN3ywxhjHWdus6bmJR+O6dxlbFXYHoYdX > fOemuIsJvjb4vl0mw9nql4kKm1MsU46gAqjP89fiCaIVPXGJjGTyqLeD48HUiNNy > YwhSCEFcj1ucQp6vG+MU+AnvQbxwnnrymjcuDWsgMehG772zWmRsg5mT3NaK4EZr > rbPnfyZSMkNMgGMjwCZQl8GlKlrsyIgnS/5zozPiSmldqJ0dEyKhPgxIfWpAIJiG > K0/k2szfVtoSBaje5eIG > =+Il1 > -----END PGP SIGNATURE----- > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >