package com.chen.dao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import com.chen.pojo.GoodsType;
import com.chen.util.JDBCUtils;
public class GoodsTypeDao {
	public boolean insertType(GoodsType goodsType) {
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			// set up connection
			conn = JDBCUtils.getConnection();
			// set up statement
			stmt = conn.createStatement();
			ArrayList<GoodsType> all = findAllWithUsername(goodsType.getUsername());
			for (GoodsType a : all) {
				if (goodsType.getGoodsType().equals(a.getGoodsType())) {
					return false;
				}
			}
			String sql = "insert into goodsType(goodsType,username) values('"
					+ goodsType.getGoodsType() + "','" + goodsType.getUsername() + "') ;";
			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;
	}
	
	public ArrayList<GoodsType> findAllWithUsername(String username) {
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		ArrayList<GoodsType> list = new ArrayList<GoodsType>();
		try {
			conn = JDBCUtils.getConnection();
			stmt = conn.createStatement();
			String sql = "select * from goodsType where username='" + username + "'";
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				GoodsType goodsType = new GoodsType();
				goodsType.setGoodsType(rs.getString("goodsType"));
				goodsType.setUsername(rs.getString("username"));
				goodsType.setId(rs.getInt("id"));
				list.add(goodsType);
			}
			return list;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			JDBCUtils.release(rs, stmt, conn);
		}
		return null;
	}
	public boolean deleteOneChickType(String username, String chickType) {
		Connection conn = null;
		Statement stmt = null;
		try {
			conn = JDBCUtils.getConnection();
			stmt = conn.createStatement();
			String delete = "delete from goodsType where username='" + username + "' and" + " goodsType='"
					+ chickType + "'";
			if (stmt.executeUpdate(delete) > 0)
				return true;
			return false;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			JDBCUtils.release(stmt, conn);
		}
		return false;
	}
}
最近下载更多
                
                新哥新奇士橙     LV5
                1月26日
            
            
        
                15719908287     LV10
                2024年6月19日
            
            
        
                泓鼎168     LV20
                2024年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日
            
            
        
最近浏览更多
                
                149965     LV1
                9月15日
            
            
        
                hubugai1     LV11
                4月25日
            
            
        
                微信网友_7371218154688512     LV4
                2月5日
            
            
        
                新哥新奇士橙     LV5
                1月26日
            
            
        
                陈小灏     LV18
                1月4日
            
            
        
                sshiqi     LV2
                2024年12月12日
            
            
        
                gnnhka     LV10
                2024年7月8日
            
            
        
                19hhhh    
                2024年6月23日
            
            
                    暂无贡献等级
            
        
                15719908287     LV10
                2024年6月19日
            
            
        
                微信网友_7041475584184320    
                2024年6月17日
            
            
                    暂无贡献等级
            
        
                
    
                