Closing a database connection

Report a typo

We have a class called DataLoader that loads data from a database via a connection. How should you modify the class so that it closes the connection when the Spring Container is shut down?

Java
class DataLoader {
    private Connection dbConnection;

    public void closeConnection() throws SQLException {
        dbConnection.close();
    }
}
Kotlin
class DataLoader(
    private val dbConnection: Connection
) {
    
    fun closeConnection() {
        dbConnection.close()
    }
}
Select one or more options from the list
___

Create a free account to access the full topic