博客
关于我
新闻发布项目——数据实现类(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/

你可能感兴趣的文章
nginx 后端获取真实ip
查看>>
Nginx 学习总结(17)—— 8 个免费开源 Nginx 管理系统,轻松管理 Nginx 站点配置
查看>>
Nginx 我们必须知道的那些事
查看>>
oauth2-shiro 添加 redis 实现版本
查看>>
OAuth2.0_授权服务配置_Spring Security OAuth2.0认证授权---springcloud工作笔记140
查看>>
Objective-C实现A-Star算法(附完整源码)
查看>>
Objective-C实现atoi函数功能(附完整源码)
查看>>
Objective-C实现base64加密和base64解密算法(附完整源码)
查看>>
Objective-C实现base85 编码算法(附完整源码)
查看>>
Objective-C实现basic graphs基本图算法(附完整源码)
查看>>
Objective-C实现BCC校验计算(附完整源码)
查看>>
Objective-C实现bead sort珠排序算法(附完整源码)
查看>>
Objective-C实现BeadSort珠排序算法(附完整源码)
查看>>
Objective-C实现bellman-ford贝尔曼-福特算法(附完整源码)
查看>>
Objective-C实现bellman-ford贝尔曼-福特算法(附完整源码)
查看>>
Objective-C实现BellmanFord贝尔曼-福特算法(附完整源码)
查看>>
Objective-C实现BF算法 (附完整源码)
查看>>
Objective-C实现binary exponentiation二进制幂运算算法(附完整源码)
查看>>
Objective-C实现binomial coefficient二项式系数算法(附完整源码)
查看>>
Objective-C实现CaesarsCiphe凯撒密码算法(附完整源码)
查看>>