articletypedao.java

来自「JSP 的博客程序含SQL数据库,及程序的配置说明 博客」· Java 代码 · 共 72 行

JAVA
72
字号
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();
	}

	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 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;
	}

	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 + =
减小字号Ctrl + -
显示快捷键?