package com.java1234.dao;

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

import com.java1234.model.PageBean;
import com.java1234.model.User;

public class UserDao {

	public ResultSet userList(Connection con,PageBean pageBean)throws Exception{
		String sql="select * from t_user limit ?,?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setInt(1, pageBean.getStart());
		pstmt.setInt(2, pageBean.getRows());
		return pstmt.executeQuery();
	}
	
	public int userCount(Connection con)throws Exception{
		String sql="select count(*) as total from t_user";
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			return rs.getInt("total");
		}else{
			return 0;
		}
	}
	
	public int userDelete(Connection con,String delId)throws Exception{
		String sql="delete from t_user where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, delId);
		return pstmt.executeUpdate();
	}
	
	public int userAdd(Connection con,User user)throws Exception{
		String sql="insert into t_user values(null,?,?,?,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, user.getName());
		pstmt.setString(2, user.getPhone());
		pstmt.setString(3, user.getEmail());
		pstmt.setString(4, user.getQq());
		return pstmt.executeUpdate();
	}
	
	public int userModify(Connection con,User user)throws Exception{
		String sql="update t_user set name=?,phone=?,email=?,qq=? where id=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, user.getName());
		pstmt.setString(2, user.getPhone());
		pstmt.setString(3, user.getEmail());
		pstmt.setString(4, user.getQq());
		pstmt.setInt(5,user.getId());
		return pstmt.executeUpdate();
	} 
}
最近下载更多
billzw  LV6 2022年2月13日
肚子疼  LV1 2021年6月23日
ttt369  LV1 2021年5月23日
vae222  LV2 2021年5月22日
CapitalQ  LV1 2021年4月19日
荒唐的羊  LV27 2021年1月19日
Dream shadow  LV9 2020年12月15日
lilinuo  LV1 2020年12月10日
dangzhongan  LV3 2020年10月7日
aaa最代码  LV14 2020年7月29日
最近浏览更多
1303891  LV1 4月14日
Henew168  LV2 2023年11月19日
微信网友_6591303770624000  LV1 2023年8月4日
1143011510  LV15 2023年2月2日
你们的代码都是我的了  LV16 2022年12月5日
 LV7 2022年7月5日
阿布屋脊  LV7 2022年6月7日
doit110 2022年3月24日
暂无贡献等级
微信网友_5846621767192576  LV1 2022年2月24日
caozongan  LV19 2022年2月21日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友