1 2 Previous Next 16 Replies Latest reply: Jul 12, 2013 9:39 AM by 938489 Go to original post RSS
      • 15. Re: com.mysql.jdbc.JDBC4Connection suspected memory leak in java
        masijade

        Sorry, I somehow missed that you were using Buffered objects already.

         

        Why do you feel the need to catch the exception in an inner block?  Are you able to do anything about it and continue with the processing?  If not, there is no reason to catch it there, let it be caught by a larger encompassing catch block.

        • 16. Re: com.mysql.jdbc.JDBC4Connection suspected memory leak in java
          938489

          Dear Masijade,

                               Its ok about the buffered Object. At times I am confused there many types what is the difference among them commonly is it its capability? Well based on your suggestion should I do this now just have one outer try and catch so in side I wont be doing any catch. So if any will it be able to capture it successfully? How about the try and finally for the statement and resultset closing leave that rite?

           

          [code]

          try{ // this the most outer try

                  dbconn = connectionPool.getConnection();

                  dbconn.setAutoCommit(false);

               

                  while ((nextChar=readBuffer.read()) != -1){         

                    capturedMessage += (char) nextChar;

                  

                    if (nextChar == '*')

                    {

           

                              Statement stmt1 = null;

                              stmt1 = dbconn.createStatement();

                              try{

                                String updateCommand1 = //query

                                count = stmt1.executeUpdate(updateCommand1);

                              }

                              finally{

                                if( stmt1 != null ){

                                 stmt1.close();

                               }

                              else{

                              System.out.println("stmt1 is null in finally close");

                               }

                             }

                      }

                 }

                }

               catch (SocketTimeoutException ex){

                     ex.printStackTrace();

               }

               catch (IOException ex){

                     ex.printStackTrace();

               }

               catch (Exception ex){

                     ex.printStackTrace(System.out);

               }   

                finally{

                  try{

                   if ( dbconn != null ){

                     dbconn.close();

                   }

                   else{

                    System.out.println("dbConn is null in finally close");

                   }

                  }

                  catch(SQLException ex){

                      ex.printStackTrace();

                  }

                  try{

                    if ( writeBuffer != null ){

                      writeBuffer.close();

                   }

                   else{

                    System.out.println("w is null in finally close");

                   }

                  }

                  catch(IOException ex){

                      ex.printStackTrace(System.out);

                  }

                 }

                }

              }

            [/code]

          1 2 Previous Next