首页>代码>apache poi操作excel实现导入导出的demo,有easyui实现的前台界面>/test_PoiDemo - 副本/src/com/asiainfo/dao/UserDao.java
package com.asiainfo.dao;

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

import com.asiainfo.model.PageBean;
import com.asiainfo.model.User;
import com.asiainfo.util.StringUtil;

public class UserDao {

	public ResultSet userList(Connection con,PageBean pageBean,User user)throws Exception{
		StringBuffer sb=new StringBuffer("select * from t_user");
		if(user != null && StringUtil.isNotEmpty(user.getName())){
			sb.append(" and name like '%"+user.getName()+"%'");
		}
		if(pageBean!=null){
			sb.append(" limit ?,?");			
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString().replace("and", "where"));
		if(pageBean!=null){
			pstmt.setInt(1, pageBean.getStart());
			pstmt.setInt(2, pageBean.getRows());
		}
		return pstmt.executeQuery();
	}
	
	public int userCount(Connection con,User user)throws Exception{
		StringBuffer sb= new StringBuffer("select count(*) as total from t_user");
		if(StringUtil.isNotEmpty(user.getName())){
			sb.append(" and name like '%"+user.getName()+"%'");
		}
		PreparedStatement pstmt=con.prepareStatement(sb.toString().replace("and", "where"));
		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();
	} 
}
最近下载更多
sunlea  LV20 2024年5月27日
是你爸爸啊100  LV5 2022年8月8日
地方撒地方的  LV2 2021年12月7日
sl0018  LV13 2021年10月3日
三岁就很帅  LV6 2021年5月12日
liuxie  LV12 2021年4月29日
hdf999  LV12 2021年4月3日
hjd3983  LV10 2021年4月2日
hhhhCCC  LV3 2021年3月30日
wyx065747  LV67 2021年3月29日
最近浏览更多
sunlea  LV20 2024年5月27日
601601lmy  LV5 2023年10月20日
1358849392  LV21 2023年10月10日
yunYUN123  LV1 2023年5月22日
hesu2020  LV1 2023年3月20日
jaonsang  LV25 2022年9月12日
是你爸爸啊100  LV5 2022年8月8日
June06  LV2 2022年4月25日
duanyui  LV3 2022年4月13日
一直都会顺利的小吴  LV5 2022年2月16日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友