重复不必要的相同列

时间:2015-05-05 06:35:00

标签: java

这个程序即时编写是从我的数据库中提取数据并将它们转换为.CSV文件,我目前正在复制相同列的错误。在这里,我的代码希望你们能提供帮助。 aots,g所有这些只是变量名。

while ( rs.next() ) {                   
    String aots= rs.getString("aots");
    if ( !myAOTS.contains( aots) ) {
        myAOTS.add(aots);

        String timeList = "";
        if ( rs.getString("aots") != null )
            timeList  = rs.getString("aots");

        String[] timeMinute  = timeList;

        for (int t = 0; t < timeMinute.length; t ++) {
            String strDate = timeMinute[t];
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            Date getDate = sdf.parse(strDate);
            getDate.getTime();

                 //Adding a while loop here stops the duplication of columns but the data in each column which is the time, would be same throughout.

                String onlf= rs.getString("onlf");
                if ( !myONLF.contains( onlf) )
                    myONLF.add(onlf);                       

                String gList = "";

                if ( rs.getString("fys") != null )
                    gList    = rs.getString("fys");

                String[] gNo = gList;

                for ( int i = 0 ; i <gNo.length ; i ++ ) {
                    if ( GDT.containsKey(gNo[i]) )
                        GDT.get(gNo[i]).put(flno, getDate.getTime());
                }                            
            for ( int i = 0 ; i < myONLF.size(); i++) {
                stringWriter.append( myONLF.get(i)  + ",");

                for ( String gNo : GDT.keySet() ) {
                    if ( GDT.get(gNo).containsKey(  myONLF.get(i)  ) )
                        GDTS.get(gNo).append(getDate.getTime() +",");
                    else
                        GDTS.get(gNo).append("0,");
                }
            }
        }
    }
}

我目前的输出是:

    col1, col2, col3, col1, col2,... 
eg1, 0,    0,   4562,   0,   0,... 
eg2, 0,    0,    0,     0,  0,... 
eg3, 0,  54652,  0,     0,   54652,... 
eg4, 4512, 0,    0,   4512,  0,... 
eg5, 0,    0,    0,     0,   0,... 

我的预期输出是:

    col1, col2, col3, col4, col5,... 
eg1, 0,    0,   4562,  0,     0,... 
eg2, 0,    0,    0,   7895,   0,... 
eg3, 0,  54652,  0,    0,     0,...  
eg4, 4512, 0,    0,    0,     0,... 
eg5, 0,    0,    0,  6521,    0,...

0 个答案:

没有答案