Consider the following Spring bean:

public class MovieRepository {

    private DataSource dataSource;

    public List<Movie> findMoviesByName(String name) {
        JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
        return jdbcTemplate.query("select name, year, rating from movies where name like ?",
                new Object[]{name},
                new RowMapper<Movie>() {
                    public Movie mapRow(ResultSet resultSet, int i) throws SQLException {
                        return new Movie(resultSet.getString("name"),
                                resultSet.getInt("year"), resultSet.getInt("rating"));


Select the statements that are correct.

(Select all acceptable answers.)

The jdbcTemplate will open a new connection to the database every time the code is executed.
The name parameter being passed unescaped to JdbcTemplate is a potential security problem.
As JdbcTemplate is thread-safe there is no need to create a new instance every time findMoviesByName() is called.
To inject a DataSource, the class needs to be annotated with @Repository.
A BeanPropertyRowMapper could be used to automatically map database rows to instances of the Movie class, provided the Movie class has the appropriate setter methods.

Java Spring Database abstraction Public


Score Distribution
Would you like to see our other questions?

We have 500+ premium hand-crafted questions for 30+ job skills and 10+ coding language. We prefer questions with small samples of actual work over academic problems or brain teasers.

Visit our question library

Private Concierge

Send us an email with an explanation of your testing needs and a list of candidates. We will create an appropriate test, invite your candidates, review their results, and send you a detailed report.

Would you like to see our tests? The following tests contain Java Spring related questions:
On the TestDome Blog

Screening Applicants: The Good, the Bad and the Ugly

Since we’re all biased and we use incorrect proxies, why not just outsource hiring to experts or recruitment agencies? After all, they’ve been screening people for many years, so they must know how to do it right?

Not really. I was surprised to discover that many experts disagree with each other. Everybody praises their pet method and criticizes the others. Many of these methods look legitimate, but are based on...