java - How to extract the value from a resulset of two statments that are union -


i have method in dao class called "getdetails". in method, union 2 select statments 2 tables same field called "main shop" & "sub shops" , put queries preparedstatement. put preparedstatement resultset.

this "getdetials" method return "details" , i'll use method in mediator called "writefile" in order print values in microsoft word "writefile(details)". in "writefile" method, there strings of values , put values of "details" respective string. , append "outputstring" each value.

on input screen, user may check "sub shops" check box , fill details of "sub shops" after checking it. if don't check, need fill "main details" , not "sub shops". if check "main shop", need print 1 letter. if check "sub shops" , fill "quantity of sub shops", need print letters letter number equal "quantity of subshops" + one(main letter). letter format totally same change value of fields of "shop name" (main or sub shop), "shop bank code" (main or sub shop) according user's choice.

in mediator, loop "writefile(details)" according quantity of "sub shops".

the problem data in different letters same (only show "main shop" data) though letter quanity correct (eg. if there 2 "sub shops", prints 3 letters). how should value of "sub shops" in subsequent letters after "main shop" letter printed.

this "writefile" method

if(flag){ this.getheading(); stringbuffer outputstring = new stringbuffer(); date date = new date();  simpledateformat formatter=new simpledateformat("dd mmmmm,yyyy");           string datestring=formatter.format(date);           details.sysdate =datestring;           string date1=(string)details.getsysdate();  if(details.getno() != null){ no=details.getno(); }else {no=" ";} if(details.bankname() != null){ bname=details.getbankname(); }else {bname = " ";}  outputstring.append('\"'); outputstring.append(date1); outputstring.append('\"'); outputstring.append(","); outputstring.append('\"'); outputstring.append(no); outputstring.append('\"'); outputstring.append(","); outputstring.append('\"'); outputstring.append(bname); outputstring.append('\"'); outputstring.append(","); outputstring.append('\"');  dos.writebytes(outputstring.tostring()); dos.flush(); dos.close(); fos.close(); } 

the query sample is

    public details getdetails (string no, string loginid, string letterid)     {         connection = dbconnection.getconnection();                 stringbuffer query = new stringbuffer();                 query.append("select to_char(trunc(sysdate),'dd month,yyyy'),a.no, b.bank_name");                 query.append("from t_newappl a,t_newappl_bank b b.no = a.no , a.no=(select no t_newappl whereno=?) , rownum=1 , status = 'pend'");                 query.append(" union ");                 query.append("select to_char(trunc(sysdate),'dd month,yyyy'),a.no,b.bank_name");                 query.append("from t_newappl a,t_newappl_bank b, newappl_sub c, t_newappl_sub_bank d a.no = c.no , c.sub_id= d.sub_id , a.no=(select no t_newappl no=?) , rownum=1 , d.status = 'spend'");                 preparedstatement preparedstatement = connection.preparestatement(query.tostring());                 preparedstatement.setstring(1,applicationno);                 preparedstatement.setstring(2,applicationno);                 resultset resultset = preparedstatement.executequery();                 while (resultset.next()){                    details = new bankdetails();                     details.no= util.trim(resultset.getstring("no"));                     details.bankname= util.trim(resultset.getstring("bank_name"));                            }                  resultset.close();                 preparedstatement.close();          return details; } 

the looping print letter is

    int retail = outletht.size();                                             int ctr = 0;                                              (int = 1; <= subshop.size ; i++ ){                                                   ctr++;                                                   letter letter = new letter(lmediator);                                                  bankdetails details = letter.printletter(applicationnumber);                                                   if (details!=null){                                                     if (ctr == 1) {                                                         if ((details.getno() == null)                                                                 && (details.getletterid() == null)                                                                 && ((details.getloginid() == null) || (details.getloginid().equals("")))) {                                                         } else {                                                             letter.databaseupdate(details);                                                         }                                                     }                                                                       letter.writefile(details);                                                                                               letter.callfile(details);                                                   context.showmessage("i01015");                                                                                                           }                                                                                          else                                                 {                                                     context.showmessage("i04004");                                                 }                         } 

your question bit hard follow. sample query output may clarify.

if you're having trouble distinguishing difference between main , sub records, suggest add column query before union.

select a, b, 'main' xtype t1 union select a, b, 'sub' xtype t2

a    b    xtype ---  ---  --- aaa  bbb  main bbb  ccc  sub 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -