package com.java.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.java.model.Info;
import com.java.util.StringUtil;


public class InfoDao {
	
	public Info infoone(Connection con,String id)throws Exception{
		String sql = "select * from info where id = ?";
		PreparedStatement pstmt = con.prepareStatement(sql);
		pstmt.setString(1,id);
		Info info = new Info();
		ResultSet rs = pstmt.executeQuery();
		while (rs.next()) {
            info.setId(rs.getInt("id"));
            info.setName(rs.getString("name"));
            info.setSex(rs.getString("sex"));
            info.setAge(rs.getInt("age"));
            info.setJoin_time(rs.getInt("join_time"));
            info.setCard(rs.getInt("card"));
        }
		return info;
	}
	
	
	
	public List<Info> infoList(Connection con,Info info)throws Exception{
		String sql = "select * from info";
		PreparedStatement pstmt = con.prepareStatement(sql);
		ResultSet rs = pstmt.executeQuery();
		List<Info> infoList = new ArrayList<Info>();
		
		while (rs.next()) {
            Info info1 = new Info();
            info1.setId(rs.getInt("id"));
            info1.setName(rs.getString("name"));
            info1.setSex(rs.getString("sex"));
            info1.setAge(rs.getInt("age"));
            info1.setJoin_time(rs.getInt("join_time"));
            info1.setCard(rs.getInt("card"));
            infoList.add(info1);
        }
		
		return infoList;
	}
	
	public int infoDelete(Connection con,String delIds)throws Exception{
		String sql="delete from info where id in("+delIds+")";
		PreparedStatement pstmt=con.prepareStatement(sql);
		return pstmt.executeUpdate();
	}
	public int infoAdd(Connection con,Info info)throws Exception{
		String sql="insert into info values(null,?,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1,info.getName());
		pstmt.setString(2,info.getSex());
		pstmt.setInt(3,info.getAge());
		pstmt.setInt(4,info.getJoin_time());
		pstmt.setInt(5,info.getCard());
		return pstmt.executeUpdate();
	}
	public int infoModify(Connection con,Info info)throws Exception{
		String sql="update info set card=?,name=?,sex=?,age=?,join_time=? where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setInt(1,info.getCard());
		pstmt.setString(2,info.getName());
		pstmt.setString(3,info.getSex());
		pstmt.setInt(4,info.getAge());
		pstmt.setInt(5,info.getJoin_time());
		pstmt.setInt(6, info.getId());
		return pstmt.executeUpdate();
	}
}
最近下载更多
yongle  LV1 2024年12月31日
xiaoaitx  LV8 2024年11月18日
houliukou  LV38 2024年6月25日
asddwh  LV13 2023年12月26日
李林112233  LV2 2023年12月4日
321170193  LV6 2023年11月11日
jiemomo  LV12 2023年10月18日
麻辣香锅加锐澳  LV7 2023年8月19日
小顾顾顾顾顾  LV4 2023年6月7日
hmdzmsl12  LV2 2023年6月1日
最近浏览更多
酷少小新  LV2 6月8日
新哥新奇士橙  LV4 1月26日
yongle  LV1 2024年12月31日
微信网友_7313889549307904 2024年12月27日
暂无贡献等级
1453666970 2024年12月27日
暂无贡献等级
ma406805131  LV19 2024年12月19日
xiaoaitx  LV8 2024年11月18日
张泽帅  LV6 2024年10月18日
赵鑫cdsaljkdfsa  LV11 2024年7月2日
琐事消极 2024年7月1日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友