Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RowMapper callback interface's mapRow can pull only one row?

 
vineet kaushik
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

This is just to check RowMapper callback interface's mapRow(ResultSet rs, int rowNum) can pull only one row??/

Thanks,
Vineet
 
vineet kaushik
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Guess, I have got the answer of my question .. I was using queryForObject(arg1,arg2,arg3) method of JDBC template instead of query(arg1,arg2,arg3) method of JDBC template.... RowMapper callback interface can pull multiple rows..

Please fell free to improve above mentioned answer.

Thanks,
Vineet
 
vineet kaushik
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is code to pull multiple rows using Rowmapper and jdbcTemplate.query(arg1,arg2).

Collection emp=jt.query("select * from employee", new RowMapper()
{
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
Employee e=new Employee();
e.setFirstName(rs.getString("first_name"));
e.setLastName(rs.getString("last_name"));
e.setAge(rs.getInt("age"));
e.setEmail(rs.getString("email"));
e.setEmpno(rs.getInt("empno"));
return e;
}
});
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to loop through the result set yourself, then you should use the ResultSetExtractor interface instead of RowMapper.

Mark
 
vineet kaushik
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct Mark,

Thanks for sharing your knowledge..

Thanks,
Vineet
 
Geeta Puttappanavar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vineet kaushik wrote:Correct Mark,

Thanks for sharing your knowledge..

Thanks,
Vineet


Hi all,

I have 2 classes (Role and User) and I want to create 1 row mapper class for both classes.

Is it possible?

Thanks in advance,
Geeta
 
Geeta Puttappanavar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geeta Puttappanavar wrote:
vineet kaushik wrote:Correct Mark,

Thanks for sharing your knowledge..

Thanks,
Vineet


Hi all,

I have 2 classes (Role and User) and I want to create 1 row mapper class for both classes.

Is it possible?

Thanks in advance,
Geeta


Resolved. Spring provides BeanPropertyRowMapper class. By using this we can achive.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic