Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with PreparedStament close

 
sreedhar Lackka
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using prepared statement to execute some query but when I verify the same code with some review tool it is giving me an error saying resource cant be released,
Please help me what to do,
Below is the code which I am writing,
Error which I am getting is,"Method may fail to clean up stream or resource " in the line where we are creating prepare statement


Please help me what to do

Regards,
Sree
 
thushara wijeratna
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what review tool are you using and what is the exact message? it seems you are releasing resources correctly.

sreedhar Lackka wrote:Hi,
I am using prepared statement to execute some query but when I verify the same code with some review tool it is giving me an error saying resource cant be released,
Please help me what to do,
Below is the code which I am writing,
Error which I am getting is,"Method may fail to clean up stream or resource " in the line where we are creating prepare statement


Please help me what to do

Regards,
Sree
 
Deepu Roy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try enclosing each of the close statements in a try/catch block. In the code, if rs1 throws an exception, the close() method will not be called on the prepared statement and connection.
 
sreedhar Lackka
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
Even I have written in my post also, the error which I am getting is "Method may fail to clean up stream or resource ".

Find bugs is the tool which I am using.

Regards,
Sree
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic