zoukankan      html  css  js  c++  java
  • JDBC getMetaData将结果集组装到List

     transient List query(Config config, Connection conn, String sql, Object paras[])
            throws SQLException
        {
            List result = new ArrayList();
            PreparedStatement pst = conn.prepareStatement(sql);
            config.dialect.fillStatement(pst, paras);
            ResultSet rs = pst.executeQuery();
            int colAmount = rs.getMetaData().getColumnCount();
            if(colAmount > 1)
            {
                Object temp[];
                for(; rs.next(); result.add(((Object) (temp))))
                {
                    temp = new Object[colAmount];
                    for(int i = 0; i < colAmount; i++)
                        temp[i] = rs.getObject(i + 1);
    
                }
    
            } else
            if(colAmount == 1)
                for(; rs.next(); result.add(rs.getObject(1)));
            DbKit.close(rs, pst);
            return result;
        }
    

      

  • 相关阅读:
    线程和进程
    Map和Collection
    数组
    泛型
    堆和栈
    Java的三大特性
    Log日志
    关系运算
    switch
    main 及Scanner
  • 原文地址:https://www.cnblogs.com/chenweichu/p/5672953.html
Copyright © 2011-2022 走看看