aspose file tools*
The moose likes Spring and the fly likes RowMapper callback interface's mapRow can pull only one row? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "RowMapper callback interface Watch "RowMapper callback interface New topic
Author

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

vineet kaushik
Greenhorn

Joined: Aug 05, 2009
Posts: 13
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

Joined: Aug 05, 2009
Posts: 13
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

Joined: Aug 05, 2009
Posts: 13
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

Joined: Feb 05, 2001
Posts: 17257
    
    6

If you want to loop through the result set yourself, then you should use the ResultSetExtractor interface instead of RowMapper.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
vineet kaushik
Greenhorn

Joined: Aug 05, 2009
Posts: 13
Correct Mark,

Thanks for sharing your knowledge..

Thanks,
Vineet
Geeta Puttappanavar
Ranch Hand

Joined: Jan 18, 2012
Posts: 43
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

Joined: Jan 18, 2012
Posts: 43
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RowMapper callback interface's mapRow can pull only one row?