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

你可能感兴趣的文章
poj 1258 Agri-Net
查看>>
poj 1286 Necklace of Beads
查看>>
POJ 1321 棋盘问题
查看>>
poj 1321(回溯)
查看>>
Qt读取注册表默认值
查看>>
poj 1679 判断MST是不是唯一的 (次小生成树)
查看>>
POJ 1703 Find them, Catch them
查看>>
POJ 1703 Find them, Catch them 并查集
查看>>
POJ 1738 An old Stone Game(石子合并)
查看>>
POJ 1740 A New Stone Game(博弈)题解
查看>>
Qt网络编程之实例二POST方式
查看>>
POJ 1765 November Rain
查看>>
poj 1860 Currency Exchange
查看>>
POJ 1961 Period
查看>>
POJ 2019 Cornfields (二维RMQ)
查看>>
poj 2057 The Lost House 贪心思想在动态规划上的应用
查看>>
poj 2057 树形DP,数学期望
查看>>
poj 2112 最优挤奶方案
查看>>
Qt编写自定义控件12-进度仪表盘
查看>>
poj 2186 Popular Cows :求能被有多少点是能被所有点到达的点 tarjan O(E)
查看>>