首页>代码>纯JSP+Tomcat的java web网络应急响应平台>/InternetSys/src/BeanProcess/CompanyTypePro.java
package BeanProcess;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import model.CompanyType;
import DatabaseConnect.ConnectDB;

public class CompanyTypePro {
	
	private Connection ct = null;
	private ResultSet rs = null;
	private PreparedStatement sta = null;
	
	public ArrayList<CompanyType> getAllCompanyType() {
		ArrayList<CompanyType> companyTypeList = new ArrayList<CompanyType>();
		String sql = "select * from companytype";
		try {
			ConnectDB cdb = new ConnectDB();
			ct = cdb.getConn();
			sta = ct.prepareStatement(sql);
			rs = sta.executeQuery();
			while (rs.next()) {
				CompanyType company = new CompanyType();
				company.setType(rs.getString("type"));
				companyTypeList.add(company);
			}
		} catch (Exception ex) {
			// TODO: handle exception
			ex.printStackTrace();
		}finally{
			this.closeM();
		}		
		return companyTypeList;
	}
	
	public boolean updateCompanyType(int id,String companyType) {
		boolean b = false;
		String sql = "UPDATE companytype SET companyname = '"+companyType+"' WHERE companyid = '"+id+"'";
		try {
			ConnectDB cdb = new ConnectDB();
			ct = cdb.getConn();
			sta = ct.prepareStatement(sql);
			int a = sta.executeUpdate();
			if (a == 1) {
				b = true;
			}
		} catch (Exception ex) {
			// TODO: handle exception
			ex.printStackTrace();
		}finally{
			this.closeM();
		}
		return b;
	}
	
	public int getTypeID(String companyType) {
		int id = 0;
		String sql = "select typeid from companytype where type = '"+companyType+"'";
		try {
			ConnectDB cdb = new ConnectDB();
			ct = cdb.getConn();
			sta = ct.prepareStatement(sql);
			rs = sta.executeQuery();;
			if (rs.next()) {
				id = rs.getInt("typeid");
			}
		} catch (Exception ex) {
			// TODO: handle exception
			ex.printStackTrace();
		}finally{
			this.closeM();
		}
		return id;
	}
	
	public String getTypeName(int typeid) {
		String id = "";
		String sql = "select type from companytype where typeid = '"+typeid+"'";
		try {
			ConnectDB cdb = new ConnectDB();
			ct = cdb.getConn();
			sta = ct.prepareStatement(sql);
			rs = sta.executeQuery();;
			if (rs.next()) {
				id = rs.getString("type");
			}
		} catch (Exception ex) {
			// TODO: handle exception
			ex.printStackTrace();
		}finally{
			this.closeM();
		}
		return id;
	}
	
	public void closeM() {
		if (rs!=null) {
			try {
				rs.close();
				rs = null;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (ct!=null) {
			try {
				ct.close();
				ct = null;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if (sta!=null) {
			try {
				sta.close();
				sta = null;
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
最近下载更多
asddwh  LV12 2023年12月29日
3305787467  LV12 2022年5月24日
839927965  LV2 2022年4月18日
famloliy  LV6 2021年8月23日
Chubby  LV3 2021年7月5日
xuzh666  LV2 2021年4月19日
ericxu1116  LV24 2021年4月13日
fanuel  LV2 2021年3月8日
xhmpmail  LV17 2021年2月23日
1qw23456  LV10 2020年12月29日
最近浏览更多
暂无贡献等级
asddwh  LV12 2023年12月29日
颜菜菜  LV2 2023年12月23日
akittyboy  LV9 2023年12月6日
ncyhhh  LV1 2023年11月26日
泓鼎168  LV19 2023年9月22日
dhbply 2023年8月16日
暂无贡献等级
TTtttH 2023年6月24日
暂无贡献等级
qazws123  LV1 2023年6月7日
fewfsdaf  LV4 2023年4月18日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友