0
package dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.krams.tutorial.oxm.SubscriptionRequest;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

public class MyMapper implements RowMapper<SubscriptionRequest> {
    public SubscriptionRequest mapRow(ResultSet rs, int rowNum) throws SQLException {
        SubscriptionRequest subscription = new SubscriptionRequest();
        subscription.setId(rs.getInt(1));
        subscription.setCity(rs.getString(2));   
        return subscription;
    }
}

this is my class at the moment, it is a mapper for my 1 table

how can i use the same mapper class for other database tables? or for each table, i must create new mapper class?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Jaanus
  • 16,161
  • 49
  • 147
  • 202

1 Answers1

3

As your RowMapper contains no state, the same instance of this class could be used for any table/select. The only question is if these tables/selects can be converted into SubscriptionRequest object and contain first int and second string column.

If not, than you must create a new RowMapper for each object you want to generate. Or use some "generic" row mapper that will produce a map from each row instead of a concrete object.

Matej Tymes
  • 1,694
  • 1
  • 16
  • 30