新建模型Account.java
package com.xpw.model;
public class Account {
private int id;
private String name;
private double money;
public Account() {
super();
}
@Override
public String toString() {
return "Account [id=" + id + ", name=" + name + ", money=" + money + "]";
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
在before_dbutils.java中使用该模型
public class before_dbutils {
@Test
public void test1() throws SQLException{
//1.获取连接对象
Connection con=C3P0Utils.getConnection();
//2.获取statement对象
Statement stmt=con.createStatement();
//3.执行查询
ResultSet rs=stmt.executeQuery("select * from account");
//4.遍历
List <Account> list = new ArrayList<Account>();
while(rs.next()){
Account account=new Account();
account.setId(rs.getInt("id"));
account.setName(rs.getString("name"));
account.setMoney(rs.getDouble("money"));
list.add(account);
}
for (Account a:list){
System.out.println(a);
}
//5.关闭
C3P0Utils.closeAll(con, stmt, rs);
}
}