title: It's good to practice using try with resources without finally in Java
body: <p>I am working with microservices in Quarkus (Java Framework). I have doubts about the closing of connections using <code>try</code>-with-resources. According to the documentation if we have an <code>AutoCloseable</code> object it should close the connection and clean up the objects. Is this really true or is it recommended to continue using <code>finally</code> to close connections?</p>
  <pre><code>package com.tmve.subscriber.repository;
  import io.agroal.api.AgroalDataSource;
  import java.sql.CallableStatement;
  import java.sql.Connection;
  import java.sql.SQLException;
  import java.sql.Types;
  import java.util.HashMap;
  
  
  public class FindPrepaidSubscriberICCIDRepository {
  
  
      public HashMap&lt;String,String&gt; getResources(AgroalDataSource defaultDataSource, String movil){
          HashMap&lt;String,String&gt; map= new HashMap&lt;&gt;();
          try(Connection conn= defaultDataSource.getConnection();
              CallableStatement stm = conn.prepareCall(&quot;{call PKG_LCL_CUENTA.B_DATOS_CLIENTE_X_MOVIL(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}&quot;))
          {
              Integer qmovil=Integer.valueOf(movil);
              stm.setInt(1,qmovil);
              stm.registerOutParameter(2, Types.VARCHAR);
              stm.registerOutParameter(3,Types.VARCHAR);
              stm.registerOutParameter(4,Types.VARCHAR);
              stm.registerOutParameter(5,Types.VARCHAR);
              stm.registerOutParameter(6,Types.VARCHAR);
              stm.registerOutParameter(7,Types.VARCHAR);
              stm.registerOutParameter(8,Types.VARCHAR);
              stm.registerOutParameter(9,Types.VARCHAR);
              stm.registerOutParameter(10,Types.VARCHAR);
              stm.registerOutParameter(11,Types.VARCHAR);
              stm.registerOutParameter(12,Types.VARCHAR);
              stm.registerOutParameter(13,Types.VARCHAR);
              stm.registerOutParameter(14,Types.INTEGER);
              stm.registerOutParameter(15,Types.INTEGER);
              stm.registerOutParameter(16,Types.VARCHAR);
              stm.registerOutParameter(17,Types.VARCHAR);
              stm.registerOutParameter(18,Types.INTEGER);
              stm.registerOutParameter(19,Types.VARCHAR);
              stm.registerOutParameter(20,Types.VARCHAR);
              stm.registerOutParameter(21,Types.VARCHAR);
              stm.registerOutParameter(22,Types.VARCHAR);
              stm.registerOutParameter(23,Types.VARCHAR);
              stm.registerOutParameter(24,Types.VARCHAR);
              stm.registerOutParameter(25,Types.INTEGER);
              stm.registerOutParameter(26,Types.INTEGER);
              stm.registerOutParameter(27,Types.VARCHAR);
              stm.registerOutParameter(28,Types.VARCHAR);
              stm.registerOutParameter(29,Types.VARCHAR);
  
              stm.execute();
  
              map.put(&quot;P_CICCID&quot;,stm.getString(27));
              return map;
  
          } catch (SQLException e) {
              map.put(&quot;error_message&quot;,e.getMessage());
              return map;
          }
      }
  
  }
  </code></pre>