0

what i'm trying to do is check if there is more than one same "childid" in the database

if its there only this code should work

for(int x=0;x<admi.size();x++){
                     if(admi.get(x).getChildid().matches(chil)){
                         no=no+1;

                            asum.get(asum.size()-1).setNooftime(no); 
                     }
                 }

here is the full method

@RequestMapping(value ="/NoOfAdmission",method = RequestMethod.GET)
public ModelAndView NoOfAdmission(ModelAndView modelAndView, ModelMap model, Map<String, Object> map,HttpServletRequest request,
        @RequestParam("syear") int syear,@RequestParam("eyear") int eyear, HttpSession session){
    String childid = (String) session.getAttribute("childid");


    List<AdmissionSummery> asum = new ArrayList<AdmissionSummery>();   
     List<Admitclinic> admitclinic = patientService.listadmitclinic();
    for(int i=syear;i<=eyear;i++){
         asum.add(new AdmissionSummery());
        int no=0;
        for(int j=0;j<admitclinic.size();j++){
            int adyear=Integer.parseInt(admitclinic.get(j).getAdmitdate().substring(0, 4));
            if(adyear==i){

                String chil = admitclinic.get(j).getChildid();
                int AdmitClinic_ID=admitclinic.get(j).getAdmitclinicid();
                 List<Admitclinic> admi=patientService.ListAdChildid(AdmitClinic_ID);
                 for(int x=0;x<admi.size();x++){
                     if(admi.get(x).getChildid().matches(chil)){
                         no=no+1;

                            asum.get(asum.size()-1).setNooftime(no); 
                     }
                 }
            }
        }
        asum.get(asum.size()-1).setDuration(syear+" "+"-"+" "+eyear);
        asum.get(asum.size()-1).setYear(i);

    }

    JRDataSource datasource = new JRBeanCollectionDataSource(asum); 

    model.addAttribute("datasourceADDreportB", datasource);

    model.addAttribute("format", "pdf");

    modelAndView = new ModelAndView("pdfReportViewaddsummeryB", model);



    return modelAndView;


}

Can someone point me how to do this?

GobyDot
  • 483
  • 3
  • 15
  • Everything you posted looks completely irrelevant to me. To know something about your data in a database, you execute database queries. Now, since you didn't tell anything about your database and what you want to check, we can't answer anything. – JB Nizet Jul 23 '14 at 07:05
  • 1
    @JBNizet in my database there is a table call "Admitclinic" in that table i have a column "childid". i want to check into the childid column for duplicate records. – GobyDot Jul 23 '14 at 07:11
  • So, edit your question, remove everything it contains, and replace it by the text in this last comment, which is your actual question. Elaborate on what you mean by "check for duplicate records". That said, if the goal is to avoid duplicates, then why don't you have a unique constraint? – JB Nizet Jul 23 '14 at 07:13
  • @GobyDot have you seen this post? http://stackoverflow.com/questions/4434118/select-statement-to-find-duplicates-on-certain-fields –  Jul 23 '14 at 07:13
  • 1
    @JBNizet i dont want to avoid anything. my goal is want to find there is any other same childid in the column. – GobyDot Jul 23 '14 at 07:23
  • 1
    So, you want to execute the query `select count(*) from Admitclinic where childid = ?`. Google for "JDBC tutorial". This is pretty basic stuff. – JB Nizet Jul 23 '14 at 07:43
  • As JBNizet said you do it with a **query**. Something like `SELECT childid, count(*) FROM table GROUP BY childid HAVING count(*) > 1` – Serge Ballesta Jul 23 '14 at 07:45
  • nooo i want to do with that java – GobyDot Jul 23 '14 at 08:36
  • @GobyDot Why do you want to try to force a square peg in a round hole? It is WAY more efficient to do it in the Database. But, if you are that persistent in doing it in Java then why not keep a `Set` of your `childid`s and just do a `.contains()` to see if the new `childid` is already taken? Also loops inside loops are usually where most performance issues arise from. You seem to have a loop in a loop in a loop. You might want to see if you can somehow optimize that code a bit. – CodeChimp Jul 23 '14 at 10:50

0 Answers0