[java] package tobaccoTrans.dao.impl; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.util.ArrayList; import java.util.List; import tobaccoTrans.util.*; import tobaccoTrans.entity.VIEW_CORP; /** * @author DWJ */ public class CorpDaoImpl extends ConnectionUtil { private Connection con = null; private Statement stmt = null; private ResultSet rs = null; /** * 方法说明:执行查询SQL语句 * 输入参数:Connection con 数据库连接 * 输入参数:String sql 要执行的SQL语句 * 返回类型:void */ public List getAllCorp(String code,String gbcode,String name,String simplename,String style,String parent) { List<VIEW_CORP> list = new ArrayList<VIEW_CORP>(); try { String sql = "select * from VIEW_CORP where 0 = 0 "; if (code != null && code.trim().length() != 0) sql = sql + " and code = '" + code + "' "; if (gbcode != null && gbcode.trim().length() != 0) sql = sql + " and gbcode = '" + gbcode + "' "; if (name != null && name.trim().length() != 0) sql = sql + " and name = '" + name + "' "; if (simplename != null && simplename.trim().length() != 0) sql = sql + " and simplename = '" + simplename + "' "; if (style != null && style.trim().length() != 0) sql = sql + " and style = '" + style + "' "; if (parent != null && parent.trim().length() != 0) sql = sql + " and parent = '" + parent + "' "; con = this.getConnection(); stmt = con.createStatement(); // 获取Staetment对象 rs = stmt.executeQuery(sql); // 执行数据库操作(查询操作) while(rs.next()) { VIEW_CORP corp = new VIEW_CORP(); corp.setCode(rs.getString("code")); corp.setGbcode(rs.getString("gbcode")); corp.setName(rs.getString("name")); corp.setSimplename(rs.getString("simplename")); corp.setStyle(rs.getString("style")); corp.setParent(rs.getString("parent")); corp.setFlag(rs.getString("flag")); list.add(corp); } } catch (Exception e) { e.printStackTrace(); }finally{ this.closeResultSet(rs); this.closeStatement(stmt); this.closeConn(con); } return list; } } |
|