版权声明:版权声明:本文为博主原创文章,未经博主允许不得转载,博客地址:http://blog.csdn.net/xpala https://blog.csdn.net/xpala/article/details/89202114
public void test1() throws SQLException {
QueryRunner qr=new QueryRunner(C3P0Utils.getDataSource());
List<Account> list=qr.query("select * from account", new ResultSetHandler<List<Account>>() {
@Override
public List<Account> handle(ResultSet rs) throws SQLException {
List<Account> list = new ArrayList<Account>();
while(rs.next()){
Account account=new Account();
account.setId(rs.getInt(1));
account.setName(rs.getString(2));
account.setMoney(rs.getDouble(3));
list.add(account);
}
return list;
}
});
for (Account a:list){
System.out.println(a);
}
}