I'm developing a web application using Spring 3.1.2, and need to create a custom row mapper. I have created a private static final class which implements RowMapper, but i'm getting the error message "The type RowMapper is not generic; it cannot be parameterized with arguments ".
All Spring related jars in my lib folder are of 3.1.2.RELEASE version. I have been unable to find anything of the sort elsewhere. Any ideas why this might be happening?
Thanks.
Here is the sample code:
public class OutPatient extends Patient{
@Pattern(regexp="[0-9]+", message="OPD No. should only contain digits.")
String opdNo;
public String getOpdNo() {
return opdNo;
}
public void setOpdNo(String opdNo) {
this.opdNo = opdNo;
}
}
DAO Class:
@Repository("dbHelper")
public class DBHelperImpl{
private JdbcTemplate jdbcTemplate;
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
public List<OutPatient> fetchOutPatients() {
String sql = "SELECT OPDNO as opdNo FROM `test`.`out_patient`";
@SuppressWarnings("unchecked") //Have to add this annotation to prevent warning
List<OutPatient> outPatients = jdbcTemplate.query(sql, new OutPatientRowMapper());
return outPatients;
}
private static final class OutPatientRowMapper implements RowMapper{ //Unable to add <OutPatient> generics here!
public OutPatient mapRow(ResultSet rs, int rowNum) throws SQLException {
OutPatient outPatient = new OutPatient();
outPatient.setOpdNo(rs.getString("opdNo"));
return outPatient;
}
}
I had this same kind of issue, Eclipse warning me about RowMapper not being generic.
So I wrote the import by hand:
import org.springframework.jdbc.core.RowMapper;
Which produced this error: The import org.springframework.jdbc.core.RowMapper collides with another import statement
So I looked at my other import statements and what do I find lurking in my Spring project:
import javax.swing.tree.RowMapper;
...I deleted that import and then everything worked as it should.
It should be something like this
List<Bank> list = t.query(sql, args, new RowMapper<Bank>() {
@Override
public Bank mapRow(ResultSet rs, int rowNum) throws SQLException {
Bank t = new Bank();
t.setName(rs.getString("name"));
return t;
}
});
This code also compiles without warnings
private static final class OutPatientRowMapper implements
RowMapper<OutPatient> {
public OutPatient mapRow(ResultSet rs, int rowNum) throws SQLException {
OutPatient outPatient = new OutPatient();
outPatient.setOpdNo(rs.getString("opdNo"));
return outPatient;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With