查看一下查询条件及数据库结果

解决方案 »

  1.   

    你就不能一次取出?分两次做什么?
      

  2.   

    建议你不要用vector存值,用Map----------
        public static List executeQuery(String sql) throws Exception
        {
            List list = new ArrayList();
            
            Connection conn = null;
            Statement  stmt = null;
            ResultSet  rs   = null;
            
            try
            {
                conn = openConnection();
                stmt = conn.createStatement();
                rs   = stmt.executeUpdate(sql);
                
                ResultSetMetaData rsmd = rs.getMetaData();
            
                while ( rs.next() )
                {
                    Map map = new HashMap();
                    
                    for ( int i = 1; i <= rsmd.getColumnCount(); i++ )
                    {
                        map.put(rsmd.getColumnName(i), rs.getString(i) == null ? "" : rs.getString(i));
                    }
                    
                    list.add(map);
                }        }
            catch ( Exception e )
            {
                e.printStackTrace();
            }
            finally
            {
                if ( rs != null ) rs.close();
                closeConnection(conn);
            }
            
            return list;
        }----------// 使用前记得import java.util.*;List list = executeQuery("select GH_Num, EPRMzhNum from S_GUAHAO  where KS_ID='"+orgId+"'and flag='no'");// 方法一:按名字取值
    for ( int i = 0; i < list.size(); i++ )
    {
        Map map = (HashMap)list.get(i);    out.println((String)mag.get("GH_Num"));
        out.println((String)mag.get("EPRMzhNum"));
    } // 方法二:遍历取值
    for ( int i = 0; i < list.size(); i++ )
    {
        Map map = (HashMap)list.get(i);    for (Iterator it = map.keySet().iterator(); it.hasNext();) 
        {
            String column_name = (String)it.next();
            out.println("column name = " + column_name);
            out.println("column value = " + (String)map.get(column_name));
        }