• 数据库中取多组数据处理


    public class GetCustomerInfo {
    // public static List main(String[] args) throws Exception{
    public List<Map> GetCustomerInfo() throws Exception{
    DBean dbean = null;
    Connection conn = null;
    PreparedStatement pst = null;
    ResultSet rs = null;
    StringBuffer sb = new StringBuffer();
    sb.append(" select t.real_name,t.gender,to_char(t.birthday,'yyyymmdd') birthday,t.certi_type,t.certi_code from t_customer t where t.status=1");
    sb.append(" and t.certi_type=1 and length(t.certi_code)=18 and t.certi_code not like '0%' AND t.certi_code not in ('102608235203284158')");
    sb.append(" and (exists (select 1 from t_contract_master t1 where t1.applicant_id=t.customer_id and t1.liability_state=1) or ");
    sb.append(" exists (select 1 from t_contract_product t2 where t2.insured_1=t.customer_id and t2.liability_state=1)) and ROWNUM<5000 ");
    try {
    dbean = new DBean();
    dbean.connect();
    conn = dbean.getConnection();
    pst = conn.prepareStatement(sb.toString());
    rs = pst.executeQuery();
    List<Map> list = new ArrayList();
    ResultSetMetaData md = rs.getMetaData();
    int columnCount = md.getColumnCount();
    while (rs.next()) {
    Map<String, String> rowData = new HashMap<String, String>();
    for (int i = 1; i <= columnCount; i++) {
    rowData.put(md.getColumnName(i), rs.getObject(i).toString());
    }
    list.add(rowData);
    }
    // System.out.println(list.get(1));
    return list;
    // System.out.println(list);
    }catch (Exception e) {
    throw e;
    } finally {
    DBean.clear(rs, pst, conn);
    }
    }
    }

    运用获取的数据:

    GetCustomerInfo a = new GetCustomerInfo();
    List<Map> m = a.GetCustomerInfo();

    i=0

    String iBirthday = m.get(i).get("BIRTHDAY").toString();
    String iCerti_code = m.get(i).get("CERTI_CODE").toString();
    String iReal_name = m.get(i).get("REAL_NAME").toString();
    String iGender = m.get(i).get("GENDER").toString();
    String iCerti_type = m.get(i).get("CERTI_TYPE").toString();

    i++

  • 相关阅读:
    设计模式之单例模式
    Java反射之调用内部类
    Java反射之修改常量值
    myBatis之入门示例
    eclipse创建maven工程
    java核心卷轴之集合
    java核心卷轴之泛型程序设计
    sublime常用快捷键
    sublime使用package control安装插件
    sublime使用技巧之添加到右键菜单、集成VI
  • 原文地址:https://www.cnblogs.com/xiaofeng91/p/13891515.html
Copyright © 2020-2023  润新知