2

I'm trying to implement the solution mentioned on SO here However, i'm getting an error "Rowmapper is abstract cannot be instantiated" and "illegal start of expression". Below is exactly what I ha

List<String> strLst  = jdbcTemplate.query(query,
                    new RowMapper {
                        public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
                            return rs.getString(1);
                        }
                    });

What if I have multiple ? in my query.

for example:

select * from table where a = ? and b = ?

how can I pass the parameters (?) into this query in the code above?

Community
  • 1
  • 1
birdy
  • 9,286
  • 24
  • 107
  • 171

1 Answers1

4

The code you are implementing makes use of an anonymous subclass of RowMapper. The correct syntax is:

new RowMapper() { ... }

You just inadvertently left out the ().

Ray Toal
  • 86,166
  • 18
  • 182
  • 232
  • I edited the question, can you also please tell me how to add more parameter values so that they can be substituted in the queyr? – birdy Oct 15 '12 at 00:32
  • The fact that you have multiple parameters does not matter. What matters is the number of columns returned. If you can be more precise and show the schema of the table you are trying to read from, I can show you how to retrieve rows using Spring JDBC no problem. – Ray Toal Oct 15 '12 at 08:48