首页>代码>java开发微博项目源码>/项目源码与数据库/MicroBlog/src/org/microblog/dao/NotifyDao.java
package org.microblog.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.microblog.po.Notify;
import org.microblog.util.DBConn;

public class NotifyDao {
	public boolean add(final Notify notify){
		String sql_addNotify = "insert into notify (n_id,u_id,u_id2,m_id,n_type,n_isread,n_time) values(null,?,?,?,?,?,?)";
		DBConn dbConn = new DBConn();
	
		int u_id = notify.getU_id();
		int u_id2 = notify.getU_id2();
		int m_id = notify.getM_id();
		int n_type = notify.getN_type();
		boolean n_isread = false;
		String n_time = notify.getN_time();
		int affectedRows = dbConn.execOther(sql_addNotify, new Object[]{u_id,u_id2,m_id,n_type,n_isread,n_time});
		return affectedRows>0?true:false;
	}
	
	public boolean read(final int n_id){
		String sql_readNotify = "update notify set n_isread = 1 where n_id = ?";
		DBConn dbConn = new DBConn();
		int affectedRows = dbConn.execOther(sql_readNotify, new Object[]{n_id});
		return affectedRows>0?true:false;
	}
	
	public boolean remove(final int n_id){
		String sql_removeNotify = "delete from notify where n_id = ?";
		DBConn dbConn = new DBConn();
		int affectedRows = dbConn.execOther(sql_removeNotify, new Object[]{n_id});
		return affectedRows>0?true:false;
	}
	
	public List<Notify> getNotifyByUserId(int u_id){
		List<Notify> notifyList = new ArrayList<Notify>();
		String sql_getNotifyByUserId = "select * from notify where u_id = ?";
		DBConn dbConn = new DBConn();
		ResultSet rs = dbConn.execQuery(sql_getNotifyByUserId, new Object[]{u_id});
		try {
			while(rs.next()){
				Notify notify = new Notify();
				notify.setN_id(rs.getInt("n_id"));
				notify.setU_id(rs.getInt("u_id"));
				notify.setU_id2(rs.getInt("u_id2"));
				notify.setM_id(rs.getInt("m_id"));
				notify.setN_type(rs.getInt("n_type"));
				notify.setN_isread(rs.getBoolean("n_isread"));
				notify.setN_time(rs.getString("n_time"));
				notifyList.add(notify);
			}
			return notifyList;
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			dbConn.closeConn();
		}
		return notifyList;
	}
	
	public long getNotifyAmountByUserId(final int u_id){
		long notifyAmount = 0;
		String sql_getNotifyByUserId = "select count(*) from notify where u_id = ? and n_isread = 0";
		DBConn dbConn = new DBConn();
		ResultSet rs = dbConn.execQuery(sql_getNotifyByUserId, new Object[]{u_id});
		try {
			while(rs.next()){
				notifyAmount = rs.getLong("count(*)");
			}
			return notifyAmount;
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			dbConn.closeConn();
		}
		return notifyAmount;
	}
}
最近下载更多
guzhoumingyue  LV1 2023年11月15日
543539666  LV7 2023年6月19日
彭星旭  LV1 2023年6月12日
qingyu1  LV1 2023年2月11日
Yingxuan  LV1 2023年1月16日
森屿elf  LV2 2022年5月29日
微信网友_5952843817488384  LV2 2022年5月10日
葡萄树下酒庄  LV9 2022年2月16日
酸欠hhhh  LV1 2021年12月22日
lk030111  LV1 2021年12月16日
最近浏览更多
pangzhihui  LV12 2月28日
ccccccc1  LV1 2023年12月26日
k666k6  LV1 2023年11月24日
guzhoumingyue  LV1 2023年11月15日
weiyoung 2023年8月6日
暂无贡献等级
三十一  LV2 2023年6月28日
罗清晨  LV11 2023年6月20日
彭星旭  LV1 2023年6月12日
543539666  LV7 2023年5月30日
dmyafda  LV5 2023年3月26日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友