How should I use try-with-resources with JDBC?

I realize this was long ago answered but want to suggest an additional approach that avoids the nested try-with-resources double block. public List<User> getUser(int userId) { try (Connection con = DriverManager.getConnection(myConnectionURL); PreparedStatement ps = createPreparedStatement(con, userId); ResultSet rs = ps.executeQuery()) { // process the resultset here, all resources will be cleaned up } catch (SQLException … Read more

Recursively list files in Java

Java 8 provides a nice stream to process all files in a tree. Files.walk(Paths.get(path)) .filter(Files::isRegularFile) .forEach(System.out::println); This provides a natural way to traverse files. Since it’s a stream you can do all nice stream operations on the result such as limit, grouping, mapping, exit early etc. UPDATE: I might point out there is also Files.find … Read more

javafx 8 compatibility issues – FXML static fields

It sounds like you are trying to inject a TextField into a static field. Something like @FXML private static TextField myTextField ; This apparently worked in JavaFX 2.2. It doesn’t work in JavaFX 8. Since no official documentation ever supported this use, it’s doesn’t really violate backward compatibility, though in fairness the documentation on exactly … Read more