反射

public ArrayList searchGysZl(String f_gysbm,String f_spmc,String selectfs,String f_bm,String zybm){
  DataBaseOperator oper = null;
  Connection conn = null;
  Statement stmt = null;
  ResultSet rs = null;
  ResultSetMetaData rsmd = null;
        StringBuffer sql = new StringBuffer();
        ArrayList list = new ArrayList();
        sql.append("select f_Csz from tbsysmsg where f_csmc='dqny'");
        try{
         oper = new DataBaseOperator();
         conn = oper.getConnection();
         stmt = conn.createStatement();
         rs = stmt.executeQuery(sql.toString());
         String f_rq="";
         if(rs.next())f_rq= rs.getString(1);
         sql.setLength(0);
         sql.append("select s.f_spbm,s.f_sphh,s.f_spmc,(select top 1 f_sptm from tb").append(f_rq).append("_sptm ");
         sql.append(" where f_xh>9 and f_spbm=s.f_spbm order by f_xh) f_sptm, f_jdrq,f_bzq,f_ggxh,f_sppp,f_sl,f_xxsl,f_jldw,s.f_xsdj, f_xjbz,f_jhkz,f_zpbz");
         sql.append(" from tb").append(f_rq).append("_spda s ").append(" inner join  tb").append(f_rq).append("_gysdz z ");
         sql.append(" on z.f_spbm=s.f_spbm and f_xh=1  inner join tbzysxcs g on g.f_zybm='").append(zybm).append("' and g.f_csbm=z.f_gysbm where ");
         sql.append("(g.f_csbm like '%").append(f_gysbm).append("')  and s.f_spmc like '%").append(f_spmc).append("%' ");
         if("0".equals(selectfs))sql.append(" and s.f_spbm like '").append(f_bm).append("%'");
         if("1".equals(selectfs))sql.append("s.f_sphh like '%").append(f_bm).append("%'");
         if("2".equals(selectfs))sql.append("exists(select f_spbm from tb").append(f_rq).append("_sptm where f_sptm='%").append(f_bm).append("%' and f_spbm=s.f_spbm)");
         sql.append(" order by s.f_spbm");
         rs = stmt.executeQuery(sql.toString());
         rsmd = rs.getMetaData();
         Class gysZl = Class.forName("cn.com.flor.gys.entity.GysSearchBean");
         Object obj = null;
         String[] names = null;
         Method method = null;
            int  j = rsmd.getColumnCount();
            names = new String[j];
            for(int i = 0;i < j;i++) {
                 String name = rsmd.getColumnName(i+1).toLowerCase();
                 names[i] = "set" + name.substring(0,1).toUpperCase() + name.substring(1);
            }
        String value = "";
         while(rs.next()){
          obj = gysZl.newInstance();//产生一个新的对象
          for(int i = 0; i < j; i++){
                 value = rs.getString(i+1);
                 method = gysZl.getMethod(names[i],new Class[]{value.getClass()});
                 method.invoke(obj,value);
                } 
          list.add(obj);
         }
        }catch(Exception ex){
         System.out.println(ex.getMessage());
        }finally{
         oper.freeConnection(conn, stmt, rs);
        }
        return list;
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值