ScalarHandler:将单个值封装、例如select count(*),求内容的条数
@Test
public void demo8()throws SQLException{
QueryRunner queryRunner =new QueryRunner(JDBCUtils2.getDataSource());
Object obj =queryRunner.query("select count(*) from account",new ScalarHandler());
System.out.println(obj);
}
KeyedHandler:将多条记录封装到一个Map集合的Map集合中。并且外面的Map集合是可以指定的(指定内层Map的其中一个属性名)。
@Test
public void demo9()throws SQLException{
QueryRunner queryRunner =new QueryRunner(JDBCUtils2.getDataSource());
Mapmap =queryRunner.query("select * from account",new KeyedHandler("name"));
for (Objectkey : map.keySet()) {
System.out.println(key+" "+map.get(key));
}
}