public KorpaBean PotrosackaKorpa(KorisnikBean kb) throws Exception{

          KorpaBean korpa = null;
          try{
            stmt=con.createStatement();
            String query1 = "select * from potrosackakorpa where korisnikID=(select KorisnikId from korisnik where korisnickoIme = '"+kb.getKorisnickoIme()+"' ) AND status="+1;
            RS=stmt.executeQuery(query1);
            //int br=0;
            if(RS.next()){
               // br++;
                    KorpaBean k = new KorpaBean();
                    k.setKorisnikId(RS.getInt("KorisnikID"));
                    k.setPKID(RS.getInt("PKID"));
                    k.setDatumNarucivanja(RS.getString("DatumNarucivanja"));
                    k.setDatumKreiranja(RS.getString("DatumKreiranja"));
                    k.setStatus(RS.getInt("Status"));
                    k.setAdresaIsporuke(RS.getString("AdresaIsporuke"));
                    k.setStatus(RS.getInt("Status"));
                    korpa=k;
                }else{
                Statement st=con.createStatement();
                String queryMax="Select MAX(PKID) as MPK from potrosackakorpa where korisnikID=(select KorisnikId from korisnik where korisnickoIme = '"+kb.getKorisnickoIme()+"' )";
                ResultSet rs=st.executeQuery(queryMax);
                int mpk=1;
                    if(rs.next()){
                        mpk=rs.getInt("MPK")+1;
                    }

                    String query="Insert Into potrosackakorpa (KorisnikID, PKID, DatumKreiranja, AdresaIsporuke, Status) values ((select KorisnikId from korisnik where korisnickoIme = '"+kb.getKorisnickoIme()+"'), "+mpk+", '"+DateFormat.getDateInstance(DateFormat.MEDIUM,new Locale("SR")).format(new Date())+"', (select adresa from korisnik where korisnickoIme = '"+kb.getKorisnickoIme()+"'),"+1+")";
                    Statement st1=con.createStatement();
                    st1.executeUpdate(query);


                    stmt=con.createStatement();
            String query111 = "select * from potrosackakorpa where korisnikID=(select KorisnikId from korisnik where korisnickoIme = '"+kb.getKorisnickoIme()+"' ) AND status="+1;
            RS=stmt.executeQuery(query111);
            //int br=0;
            if(RS.next()){
               // br++;
                    KorpaBean k = new KorpaBean();
                    k.setKorisnikId(RS.getInt("KorisnikID"));
                    k.setPKID(RS.getInt("PKID"));
                    k.setDatumNarucivanja(RS.getString("DatumNarucivanja"));
                    k.setDatumKreiranja(RS.getString("DatumKreiranja"));
                    k.setStatus(RS.getInt("Status"));
                    k.setAdresaIsporuke(RS.getString("AdresaIsporuke"));
                    k.setStatus(RS.getInt("Status"));
                    korpa=k;
                }
                }
            Statement stmt1=con.createStatement();
            String query2 = "select * from stavkapk where KorisnikID="+korpa.getKorisnikId()+" AND PKID="+korpa.getPKID();
            ResultSet RS=stmt1.executeQuery(query2);

            while(RS.next()){
                StavkaPKBean spk=new StavkaPKBean();
                spk.setKorisnikId(korpa.getKorisnikId());
                spk.setPKID(korpa.getPKID());
                spk.setRB(RS.getInt("RB"));
                spk.setProizvod(getProizvodByID(RS.getInt("proizvodID")));
                spk.setKolicina(RS.getInt("kolicina"));
                korpa.getStavke().add(spk);
            }
        //if(br==0) {
          //  throw new Exception("Nema unetih proizvoda!");
        //}
      }catch(Exception e){
              throw new Exception("Greska pri pregledu potrosacke korpe! "+e);
          }
          return korpa;
      }