I just tried converting some simple JDBC code usin...
# announcements
d
I just tried converting some simple JDBC code using the Java -> Kotlin converter built into IntelliJ IDEA and gut erroneous result. Java code:
Copy code
public void delete(Event event) {
        String query = "DELETE FROM Event WHERE id = ?;";
        try (Connection c = connectionPoolService.getConnection();
             PreparedStatement ps = c.prepareStatement(query)) {
            ps.setLong(1, event.getId());
            ps.executeUpdate();
        } catch (SQLException ex) {
            logger.error("Deleting event failed", ex);
        }
    }
Generated Kotlin code:
Copy code
fun delete(event: Event) {
        val query = "DELETE FROM Event WHERE id = ?;"
        try {
            connectionPoolService.connection.use { c ->
                c.prepareStatement(query).use({ ps ->
                    ps.setLong(1, event.id)
                    ps.executeUpdate()
                })
            }
        } catch (ex: SQLException) {
            logger.error("Deleting event failed", ex)
        }
    }