2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

How can I use ResultSetExtractor in Spring ?

I have some data in database and want to retrieve those using ResultSetExtractor but unable to find proper example on this. Please suggest with some good example.
userimage

Here is the complete example of ResultSetExtractor


package kodetalk.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.ResultSetExtractor;
import domainmodel.Person;

public class PersonResultSetExtractor implements ResultSetExtractor {

    @Override
    public Object extractData(ResultSet rs) throws SQLException {
        Person person = new Person();
        person.setFirstName(rs.getString(1));
        person.setLastName(rs.getString(2));
        return person;
    }

}


package kodetalk.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import org.springframework.jdbc.core.RowMapper;

public class PersonRowMapper implements RowMapper {

    @Override
    public Object mapRow(ResultSet rs, int line) throws SQLException {
        PersonResultSetExtractor extractor = new PersonResultSetExtractor();
        return extractor.extractData(rs);
    }

}

Answer is