package com.chen.dao; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import com.chen.pojo.PullChickens; import com.chen.util.JDBCUtils; /** * 出货 * @author chenguoji * */ public class PullChickDao { public void deleteAll() { Connection conn = null; Statement stmt = null; ResultSet rs = null; try { // set up connection conn = JDBCUtils.getConnection(); // set up statement stmt = conn.createStatement(); String sql = "delete from pullChick"; stmt.executeUpdate(sql); } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtils.release(rs, stmt, conn); } } public ArrayList<PullChickens> findAll() { Connection conn = null; Statement stmt = null; ResultSet rs = null; ArrayList<PullChickens> list = new ArrayList<PullChickens>(); try { conn = JDBCUtils.getConnection(); stmt = conn.createStatement(); String sql = "select * from pullChick"; rs = stmt.executeQuery(sql); while (rs.next()) { PullChickens PullChick = new PullChickens(); PullChick.setChickType(rs.getString("chickType")); PullChick.setPrice(rs.getBigDecimal("price")); PullChick.setTare(rs.getBigDecimal("tare")); PullChick.setSuttle(rs.getBigDecimal("suttle")); PullChick.setSumWeight(rs.getBigDecimal("sumWeight")); PullChick.setSumPrice(rs.getBigDecimal("sumPrice")); list.add(PullChick); } if (list.size() == 0) { return null; } return list; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } finally { JDBCUtils.release(rs, stmt, conn); } return null; } public boolean insert(PullChickens PullChickens) { Connection conn = null; Statement stmt = null; ResultSet rs = null; Boolean flag = false; try { // set up connection conn = JDBCUtils.getConnection(); // set up statement stmt = conn.createStatement(); String selectTable = "select * from pullChick"; rs = stmt.executeQuery(selectTable); while (rs.next()) { System.out.print(PullChickens.getChickType() + rs.getString("chickType")); if (PullChickens.getChickType().equals(rs.getString("chickType"))) { flag = true; break; } } if (flag) { String sqlAdd = "update pullChick" + " set tare=tare+" + PullChickens.getTare() + ",suttle=suttle+" + PullChickens.getSuttle() + ",price=price+" + PullChickens.getPrice() + ",sumPrice=sumPrice+" + PullChickens.getSumPrice() + ",sumWeight=sumWeight+" + PullChickens.getSumWeight() + " where chickType='" + PullChickens.getChickType() + "' ;"; int re = stmt.executeUpdate(sqlAdd); if (re > 0) { return true; } return false; } else { String sql = "insert into pullChick (chickType,price,tare,suttle,sumWeight,sumPrice) values('" + PullChickens.getChickType() + "'," + PullChickens.getPrice() + "," + PullChickens.getTare() + "," + PullChickens.getSuttle() + "," + PullChickens.getSumWeight() + "," + PullChickens.getSumPrice() + ") ;"; int num = stmt.executeUpdate(sql); if (num > 0) { return true; } return false; } } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtils.release(rs, stmt, conn); } return false; } }
最近下载更多
15719908287 LV9
6月19日
泓鼎168 LV20
4月11日
adap12345 LV5
2023年6月14日
1379585889 LV11
2023年6月12日
静静123456 LV3
2023年5月18日
ly4910 LV3
2023年3月12日
fantesy LV17
2023年2月16日
FZJFZJ LV3
2023年1月10日
dongren88 LV5
2022年12月3日
fdgdgkjn LV4
2022年11月30日
最近浏览更多
gnnhka LV10
7月8日
19hhhh
6月23日
暂无贡献等级
15719908287 LV9
6月19日
微信网友_7041475584184320
6月17日
暂无贡献等级
kaye7549317
3月18日
暂无贡献等级
微信网友_6906962132258816 LV7
3月16日
2010160433 LV3
3月10日
xiaojie93 LV2
3月1日
80730176 LV7
2月1日
Liang朝伟 LV1
1月6日