0

I have a query which needs to be executed. There were tons of examples of rowmapper all over so I took some brief idea from there.

So I have a huge query which has joins of multiple tables and it extracts some data. Depending on the data it retrieves I have constructed a class which implements rowmapper interface where all the details of the db are mapped accordingly to a bean that I have created.

Now in order to execute this query in the repository class I have written something like:

class mapthaticreated implements Rowmapper<bean>
{

public bean maprow(ResultSet rs, int row){

Bean b = new Bean();
B.setName(rs.getString(“NAME”));
...,,,,

In the repository class in one method I have written:

void getDetails(string sql){

Rowmapper <bean> row = new mapperthaticreated()
Jdbc.query(sql,mapper)

I'm getting a NullPointerException. Please help me know what am I doing wrong??

lospejos
  • 1,976
  • 3
  • 19
  • 35
Anant Majhi
  • 45
  • 1
  • 6

1 Answers1

0

Well, since you didn't provide any code, RowMapper needs to implement mapRow.

So it would be something like this (using Java 7):

jdbcTemplate.query(sqlQuery, new RowMapper<YourBean>() {
   @Override
   public YourBean mapRow(ResultSet rs, int rowNum) throws SQLException {
       YourBean bean = new YourBean();
       bean.setName(rs.getString("name"));
       //And so on...
   }
});
Leonardo
  • 1,263
  • 7
  • 20
  • 51