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

你可能感兴趣的文章
php使用memcached扩展的一个BUG
查看>>
PHP内核介绍及扩展开发指南—基础知识
查看>>
PHP写日志fwrite和file_put_contents的区别与性能
查看>>
PHP函数
查看>>
PHP函数__autoload失效原因(与smarty有关)
查看>>
PHP函数操作数字和汉字互转(100以内)
查看>>
PHP函数方法
查看>>
PHP删除指定目录下的所有文件和文件夹 | 删除指定文件
查看>>
php判断ip黑名单程序代码
查看>>
php判断复选框是否被选中的方法
查看>>
PHP判断指定目录下是否存在文件
查看>>
php判断数组是否为空
查看>>
PHP判断数组是否有重复值、获取重复值
查看>>
PHP利用正则表达式实现手机号码中间4位用星号(*)替换显示
查看>>
PHP加密与安全的最佳实践
查看>>
PHP区分 企业微信浏览器 | 普通微信浏览器 | 其他浏览器
查看>>
php原生代码怎么连表查询,PHP tp5中使用原生sql查询代码实例
查看>>
PHP去掉转义符
查看>>
php反射api
查看>>
PHP反射ReflectionClass、ReflectionMethod 入门教程
查看>>