It ensures automatic resource closure. Frame the concept in practical terms so you can explain it during interview discussion.
Try-with-resources simplifies the cleanup of JDBC resources, such as Connections, Statements, and ResultSets, by automatically closing them when the block exits. This reduces the risk of resource leaks. For example, when querying a database for product details, using try-with-resources ensures the ResultSet is closed properly, even if an exception occurs.
Additional Notes
What are the benefits of using try-with-resources in JDBC?