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

📄 articletypedao.java

📁 我的博客
💻 JAVA
字号:
package com.yxq.dao;

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

import com.yxq.toolsbean.DB;
import com.yxq.valuebean.ArticleTypeBean;

public class ArticleTypeDao
{
	private DB connection = null;

	public ArticleTypeDao()
	{
		connection = new DB();
	}
	
	//  oper为一个String类型变量,用来表示要进行的操作;single为ArticleBean类对象,用来存储某个文章的信息
	public boolean operationArticleType(String operation, ArticleTypeBean single)
	{
		String sql = null;
		if (operation.equals("add"))
			sql = "insert into tb_articleType values ('" + single.getTypeName()
					+ "','" + single.getTypeInfo() + "')";
		if (operation.equals("modify"))
			sql = "update tb_articleType set articleType_name='"
					+ single.getTypeName() + "',articleType_info='"
					+ single.getTypeInfo() + "' where articleType_id="
					+ single.getId();
		if (operation.equals("delete"))
			sql = "delete from tb_articleType where articleType_id="
					+ single.getId();
		boolean flag = connection.executeUpdate(sql);
		return flag;
	}

	public ArticleTypeBean queryTypeSingle(int id)  // ArticleTypeBean 封装了 文章的一些信息
	{
		ArticleTypeBean typeBean = null;
		String sql = "select * from tb_articleType where articleType_id=" + id;
		ResultSet rs = connection.executeQuery(sql);
		if (rs != null)
		{
			try
			{
				if (rs.next())
				{
					typeBean = new ArticleTypeBean();
					typeBean.setId(rs.getInt(1));
					typeBean.setTypeName(rs.getString(2));
					typeBean.setTypeInfo(rs.getString(3));
				}
			} catch (SQLException e)
			{
				typeBean = null;
				e.printStackTrace();
			}
		}
		return typeBean;
	}

	@SuppressWarnings("unchecked")
	public List queryTypeList()
	{
		List typelist = null;
		String sql = "select * from tb_articleType";
		ResultSet rs = connection.executeQuery(sql);
		if (rs != null)
		{
			typelist = new ArrayList();
			try
			{
				while (rs.next())
				{
					ArticleTypeBean typeBean = new ArticleTypeBean();
					typeBean.setId(rs.getInt(1));
					typeBean.setTypeName(rs.getString(2));
					typeBean.setTypeInfo(rs.getString(3));
					typelist.add(typeBean);
				}
			} catch (SQLException e)
			{
				e.printStackTrace();
			}
		}
		return typelist;
	}

}

⌨️ 快捷键说明

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