博客
关于我
新闻发布项目——数据实现类(categoryTBDaoImpl)
阅读量:592 次
发布时间:2019-03-11

本文共 3412 字,大约阅读时间需要 11 分钟。

package bdqn.newsMange.Dao.Impl;

import java.sql.ResultSet;import java.sql.SQLException;import java.util.ArrayList;import java.util.List;import bdqn.newsMange.Dao.BaseDao;import bdqn.newsMange.Dao.categoryTBDao;import bdqn.newsMange.entity.categoryTB;

/**

  • ???????????*/public class categoryTBDaoImpl extends BaseDao implements categoryTBDao {

    // ??????public List

    getAllCategories() {String sql = "select categoryID, categoryName from categoryTB";List
    typelist = new ArrayList<>();try {ResultSet rs = executeQuery(sql, null);while (rs.next()) {categoryTB cate = new categoryTB();cate.setCategoryID(rs.getInt(1));cate.setCategoryName(rs.getString(2));typelist.add(cate);}} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} finally {closeAll();}return typelist;}

    // ????public int addCategory(categoryTB cate) {int rel = 0;String sql = "insert into categoryTB (categoryName) values (?)";List params = new ArrayList<>();params.add(cate.getCategoryName());try {rel = executeUpdate(sql, params);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} finally {closeAll();}return rel;}

    // ??????public int updateCategory(categoryTB cate) {int rel = 0;String sql = "update categoryTB set categoryName = ? where categoryId = ?";List params = new ArrayList<>();params.add(cate.getCategoryName());params.add(cate.getCategoryID());try {rel = executeUpdate(sql, params);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} finally {closeAll();}return rel;}

    // ????public int delCategory(int id) {int rel = 0;String sql = "delete from categoryTB where categoryId = ?";List params = new ArrayList<>();params.add(id);try {rel = executeUpdate(sql, params);} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} finally {closeAll();}return rel;}

    // ????????public categoryTB getCateByName(String categoryName) {categoryTB cate = null;String sql = "select categoryID, categoryName from categoryTB where categoryName = ?";List params = new ArrayList<>();params.add(categoryName);try {ResultSet rs = executeQuery(sql, params);if (rs.next()) {cate = new categoryTB();cate.setCategoryID(rs.getInt("categoryId"));cate.setCategoryName(rs.getString("categoryName"));}} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} finally {closeAll();}return cate;}

    // ??ID????public categoryTB getCateById(int categoryId) {categoryTB cate = null;String sql = "select categoryID, categoryName from categoryTB where categoryId = ?";List params = new ArrayList<>();params.add(categoryId);try {ResultSet rs = executeQuery(sql, params);if (rs.next()) {cate = new categoryTB();cate.setCategoryID(rs.getInt(1));cate.setCategoryName(rs.getString(2));}} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} finally {closeAll();}return cate;}

    // ????????????public int isCategoryExist(String categoryName) {int rel = 0;String sql = "select categoryID from categoryTB where categoryName = ?";List params = new ArrayList<>();params.add(categoryName);try {ResultSet rs = executeQuery(sql, params);if (rs.next()) {rel = 1;}} catch (ClassNotFoundException e) {e.printStackTrace();} catch (SQLException e) {e.printStackTrace();} finally {closeAll();}return rel;}}

转载地址:http://irktz.baihongyu.com/

你可能感兴趣的文章
python基础之字符编码
查看>>
python基础之多线程与多进程(二)
查看>>
Python基础——MySQL数据库基本操作
查看>>
Python基础_列表 list
查看>>
python基础---->常用模块
查看>>
Python基础(2):控制结构
查看>>
Python基础 | 关于“循环”那些事
查看>>
python系列【仅供参考】:python 远程rdp
查看>>
python基于flask搭建http服务(四)—— Docker容器化部署
查看>>
Python块键盘/鼠标输入
查看>>
python在使用HTMLTestRunner时,报告为空,错误提示<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf_8'>...
查看>>
python在gpu上运行_【python】python开启GPU加速
查看>>
Python在def函数中使用for循环
查看>>
Python在def函数中使用for循环
查看>>
Python在Conda环境中,但在Windows虚拟环境中没有激活
查看>>
python系列【仅供参考】:python pip 错误 ModuleNotFoundError: No module named pip._internal 解决办法
查看>>
python图像条状状噪声,使用PYTHON PIL从验证码图像中删除背景嘈杂的线条
查看>>
Python图像处理:从内存加载jpeg
查看>>
python固定后缀(名物化词汇)词频统计:抽取+统计+可视化
查看>>
python商品评论数据采集与分析可视化系统 Flask框架 requests爬虫 NLP情感分析 毕业设计 源码
查看>>