正常处理数据库查到的数据
conn = DaoFactory.GetgetDBConn().getConn();
st = conn.createStatement();
rs = st.executeQuery("select * from product");
while (rs.next()) {
Product product = new Product();
product.setId(rs.getInt("id"));
product.setName(rs.getString("name"));
product.setIntroduce(rs.getString("introduce"));
product.setNumber(rs.getInt("number"));
product.setNewPrize(rs.getDouble("new_prize"));
product.setBandType(rs.getString("band_type"));
product.setOldPrize(rs.getDouble("old_prize"));
product.setPicture(rs.getString("picture"));
product.setPricetype(rs.getString("pricetype"));
product.setSportType(rs.getString("sport_type"));
product.setType(rs.getInt("type"));
list.add(product);
dbutil处理数据
ResultSetHandler<List<Product>> resultHandler = new BeanListHandler<Product>(Product.class);
List<Product> list1 = new ArrayList();
GetDBConn getDBConn = DaoFactory.GetgetDBConn();
Connection conn = getDBConn.getConn();
if(conn!=null) {
QueryRunner runner = new QueryRunner();
try {
List<Product> productList = runner.query(conn, "SELECT * FROM product where name=?", resultHandler,uname);
for(Product pro: productList ) {
Product product = new Product();
product.setId(pro.getId());
product.setName(pro.getName());
product.setIntroduce(pro.getIntroduce());
product.setNumber(pro.getNumber());
product.setNewPrize(pro.getNewPrize());
product.setBandType(pro.getBandType());
product.setOldPrize(pro.getOldPrize());
product.setPicture(pro.getPicture());
product.setPricetype(pro.getPricetype());
product.setSportType(pro.getSportType());
product.setType(pro.getType());
list1.add(product);
}
} catch (SQLException e) {
e.printStackTrace();
}
DbUtils.closeQuietly(conn);
}
System.out.println(list1);
return list1;
写删除的sql语句时
int row = runner.update(conn, "delete from product where id=?",id);
if(row>0){
flag = true;
}