首页>代码>jsp+servlet整合bootstrap开发新闻后台管理系统>/新闻发布系统/News/src/com/java1234/dao/NewsTypeDao.java
package com.java1234.dao;

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

import com.java1234.model.NewsType;

public class NewsTypeDao {

	public List<NewsType> newsTypeList(Connection con)throws Exception{
		List<NewsType> newsTypeList=new ArrayList<NewsType>();
		String sql="select * from t_newsType";
		PreparedStatement pstmt=con.prepareStatement(sql);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next()){
			NewsType newsType=new NewsType();
			newsType.setNewsTypeId(rs.getInt("newsTypeId"));
			newsType.setTypeName(rs.getString("typeName"));
			newsTypeList.add(newsType);
		}
		return newsTypeList;
	}
	
	public NewsType getNewsTypeById(Connection con,String newsTypeId)throws Exception{
		NewsType newsType=new NewsType();
		String sql="select * from t_newsType where newsTypeId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsTypeId);
		ResultSet rs=pstmt.executeQuery();
		if(rs.next()){
			newsType.setNewsTypeId(rs.getInt("newsTypeId"));
			newsType.setTypeName(rs.getString("typeName"));
		}
		return newsType;
	}
	
	public int newsTypeAdd(Connection con,NewsType newsType)throws Exception{
		String sql="insert into t_newsType values(null,?)";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsType.getTypeName());
		return pstmt.executeUpdate();
	}
	
	public int newsTypeUpdate(Connection con,NewsType newsType)throws Exception{
		String sql="update t_newsType set typeName=? where newsTypeId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsType.getTypeName());
		pstmt.setInt(2, newsType.getNewsTypeId());
		return pstmt.executeUpdate();
	}
	
	public int newsTypeDelete(Connection con,String newsTypeId)throws Exception{
		String sql="delete from t_newsType where newsTypeId=?";
		PreparedStatement pstmt=con.prepareStatement(sql);
		pstmt.setString(1, newsTypeId);
		return pstmt.executeUpdate();
	}
}
最近下载更多
pangzhihui  LV14 2024年3月14日
syczzxj  LV10 2023年6月6日
微信网友_5975606834761728  LV3 2023年3月21日
2716804680  LV9 2023年3月10日
Roninljy  LV1 2023年2月16日
1721281527  LV2 2022年12月28日
zhang123zz  LV1 2022年10月30日
benbosn  LV15 2022年8月31日
李海洋  LV12 2022年5月31日
ewan007  LV30 2022年3月11日
最近浏览更多
krispeng  LV15 5月29日
陈小灏  LV18 1月4日
qwqwx585160  LV2 2024年12月15日
文巾方 2024年10月30日
暂无贡献等级
asdfgh112 2024年7月4日
暂无贡献等级
暂无贡献等级
bankroll  LV5 2024年6月13日
玖零定制问题修复  LV34 2024年4月4日
WBelong  LV8 2023年12月27日
wttttts  LV2 2023年12月24日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友