package dao;

import Util.StringUtil;
import model.Secondary;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class SecondaryDao {

    //学院添加
    public int add(Connection con, Secondary secondary) throws Exception {
        String sql = "insert into secondary values(null,?,?)";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, secondary.getSecondary_name());
        pstmt.setString(2, secondary.getSecondary_desc());

        return pstmt.executeUpdate();
    }

    //查询学院
    public ResultSet list(Connection con, Secondary secondary) throws Exception {
        StringBuilder strb = new StringBuilder("select*from secondary");
        if (StringUtil.isNotEmpty(secondary.getSecondary_name())) {
            strb.append(" and secondary_name like '%" + secondary.getSecondary_name() + "%'");
        }
        PreparedStatement pstmt = con.prepareStatement(strb.toString().replace("and", "where"));
        return pstmt.executeQuery();
    }

    //删除学院
    public int delete(Connection con, String id) throws Exception {
        String sql = "delete from secondary where id=?";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, id);
        return pstmt.executeUpdate();
    }

    //修改学院
    public int update(Connection con, Secondary secondary) throws Exception {
        String sql = "update secondary set secondary_name=? ,secondary_desc=? where id =?";
        PreparedStatement pstmt = con.prepareStatement(sql);
        pstmt.setString(1, secondary.getSecondary_name());
        pstmt.setString(2, secondary.getSecondary_desc());
        pstmt.setInt(3, secondary.getId());
        return pstmt.executeUpdate();
    }
}
最近下载更多
wanglinddad  LV55 3月26日
weilaizhisheng  LV21 2023年11月30日
卢本伟不开挂  LV4 2023年9月3日
微信网友_6000801142263808  LV3 2023年6月18日
wipeout  LV1 2023年6月17日
mayong1234  LV6 2023年6月15日
huangzy  LV12 2023年6月7日
lsglsg9  LV22 2023年6月4日
syfzsyfz  LV1 2023年5月23日
全栈小白  LV34 2023年4月25日
最近浏览更多
lzx602  LV3 4月15日
玖零定制问题修复  LV34 4月4日
fff2003  LV6 1月3日
暂无贡献等级
erqiu2013  LV18 2023年12月27日
gcfwgdfgh 2023年12月22日
暂无贡献等级
颜菜菜  LV2 2023年12月19日
微信网友_6785176779689984 2023年12月19日
暂无贡献等级
zn2020  LV1 2023年12月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友