Witam, mam problem nie wiem co może być przyczyną tego tworzę tablicę obiektów "objectKlient" na starcie ją inicjalizację dla testu i zapisuje danymi testowymi, jednak po przejściu pętli, dane tablicy są kasowane a pozostaje jeden ostatni rekord z pętli.
public Object[][] pobierzklient(){
this._4katyKlienci = this.db4katy.getCollection("4katy.klienci");
int iloscWierszy = (int) this._4katyKlienci.getCount();
System.out.println("Nazwa kolekcji: "+ this._4katyKlienci.getName()+", "+"iloscWierszy: " + iloscWierszy);
/* BŁĘDNA INCIALIZACJA
Object [][]objectKlientow = new Object[][]{
{"pobierzKlienta","pobierzKlienta","pobierzKlienta","pobierzKlienta"},
{"pobierzKlienta","pobierzKlienta","pobierzKlienta","pobierzKlienta"}
};
*/
// Poprawna
Object[][] objectKlientow = new Object[iloscWierszy][4];
String imie;
String nazwisko;
String email;
String telefon;
try(DBCursor cursors = this._4katyKlienci.find()){
if(cursors.count() > 0){
while(cursors.hasNext()){
cursors.next();
imie = cursors.curr().get("imie").toString();
System.out.println("imie: " + imie);
nazwisko = cursors.curr().get("nazwisko").toString();
System.out.println("nazwisko: " + nazwisko);
email = cursors.curr().get("email").toString();
System.out.println("email: " + email);
telefon = cursors.curr().get("telefon").toString();
System.out.println("telefon: " + telefon);
System.out.println("while.cursors.hasNext(): " + cursors.hasNext());
System.out.println("cursors.numSeen(): " + cursors.numSeen());
/* BŁĄD
objectKlientow = new Object[][]{{imie,nazwisko,email,telefon}};
*/
// Poprawne przypisanie wartosci
objectKlientow[cursors.numSeen() -1][0] = imie;
objectKlientow[cursors.numSeen() - 1][1] = nazwisko;
objectKlientow[cursors.numSeen() - 1][2] = email;
objectKlientow[cursors.numSeen() - 1][3] = telefon;
System.out.println("Pobrano: " + (int) ((cursors.numSeen()*100)/iloscWierszy) + "%");
}
}
System.out.println("objectlientow: " + objectKlientow.length);
}
return objectKlientow;
}
Rozwiązane :)