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

你可能感兴趣的文章
Objective-C实现sha256算法(附完整源码)
查看>>
Objective-C实现shell sort希尔排序算法(附完整源码)
查看>>
Objective-C实现SinglyLinkedList单链表算法(附完整源码)
查看>>
Objective-C实现skew heap倾斜堆算法(附完整源码)
查看>>
Objective-C实现Skip List跳表算法(附完整源码)
查看>>
Objective-C实现slack message松弛消息算法(附完整源码)
查看>>
Objective-C实现slow sort慢排序算法(附完整源码)
查看>>
Objective-C实现tanh函数功能(附完整源码)
查看>>
Objective-C实现z-algorithm算法(附完整源码)
查看>>
Objective-C实现zellers congruence泽勒一致算法(附完整源码)
查看>>
Objective-C实现Zero One Knapsack零一背包计算算法(附完整源码)
查看>>
Objective-C实现一个Pangram字符串至少包含一次所有字母算法(附完整源码)
查看>>
Objective-C实现一个通用的堆算法(附完整源码)
查看>>
Objective-C实现一分钟倒计时(附完整源码)
查看>>
Objective-C实现三次样条曲线(附完整源码)
查看>>
Objective-C实现上传文件到FTP服务器(附完整源码)
查看>>
Objective-C实现两数之和问题(附完整源码)
查看>>
Objective-C实现中文模糊查询(附完整源码)
查看>>
Objective-C实现串口通讯(附完整源码)
查看>>
Objective-C实现串逐位和(附完整源码)
查看>>