Java - Best Practice - FAQ
1] Here myListConsistOfSQL is the List<String> which consist of SQL scripts for execution PreparedStatement ps=null; try{ conn=getMyDBConnection(); for(String sql: myListConsistOfSQL) { ps = conn.prepareStatement(sql); ps.addBatch(); ps.executeBatch(); } } Catch(Exception e) { throw new e; } finally { if(ps!=null) { ps.close(); } if(conn!=null) { conn.close(); } } 2] Map object to print the key and values using for each loop myDataMap.forEach((key, value) -> log.info("Details:: " + key + ":" + value)); myDataList.forEach(msg -> log.info(msg)); 3] Logger message utility class to hold details in list import java.util.ArrayList; import java.util.List; public class MessagesUtil { ...