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日

最近浏览