How to properly use try-with-resources in Database connection?
问题 I have looked around, but can't seem to find the answer to my question. Here is the context : I have to connect to a Database in my Java program and execute a SQL request that I have no control over and don't know in advance. To do that I use the code below. public Collection<HashMap<String, String>> runQuery(String request, int maxRows) { List<HashMap<String, String>> resultList = new ArrayList<>(); DataSource datasource = null; try { Context initContext = new InitialContext(); datasource =