⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 categorydao.java

📁 是一个Bug系统
💻 JAVA
字号:
package com.runwit.ebookstore.services.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.runwit.common.db.DbDAO;
import com.runwit.ebookstore.model.CategoryModel;
import com.runwit.ebookstore.services.ICategoryServices;

public class CategoryDAO extends DbDAO implements ICategoryServices {

	public boolean createCategory(CategoryModel model) {
		String sql = "insert into categories(name, parent_id) values('"+
		model.getName()+"',"+model.getParentId()+")";
		int iRet = 0;
		try{
			iRet = updateBySql(sql);
		}catch(SQLException ex) {
			ex.printStackTrace();
		}
		return iRet == 1;
	}
	
	public CategoryModel getModel(int oid) {
		try
		{
			List alRet = queryBySql("select * from categories where category_id="+oid);
			if(alRet.size() > 0)
				return (CategoryModel)alRet.get(0);
		}catch(SQLException ex) {
			ex.printStackTrace();
		}
		
		return null;
	}

	public List listCategory(int parentId) {
		String sql = "select * from categories where parent_id="+parentId;
		try{
			return queryBySql(sql);
		}catch(SQLException ex) {
			ex.printStackTrace();
		}
		
		return null;
	}
	
	public List listAllCategory() {
		String sql = "select * from categories";
		try{
			return queryBySql(sql);
		}catch(SQLException ex) {
			ex.printStackTrace();
		}
		
		return null;
		
	}

	public boolean removeCategories(int categoryId) {
		String sql = "delete categories where parent_id=" + categoryId
				+ " or category_id=" + categoryId;
		try
		{
			return updateBySql(sql) > 0;
		}catch(SQLException ex) {
			ex.printStackTrace();
		}
		return false;
	}

	public boolean updateCategory(CategoryModel model) {
		String sql = "update categories set name=? where category_id=?";
		Object[] objs = {model.getName(), new Integer(model.getCategoryId())};
		int[] types = {STRING_TYPE, INT_TYPE};
		try
		{
			return updateBySql(sql, objs, types) == 1;
		}catch(SQLException ex) {
			ex.printStackTrace();
		}
		return false;
	}
	
	@Override
	public Object mapRowToModel(ResultSet rs) throws SQLException{
		CategoryModel m = new CategoryModel();
		m.setCategoryId(rs.getInt("category_id"));
		m.setName(rs.getString("name"));
		m.setParentId(rs.getInt("parent_id"));
		
		return m;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -