-2

I created a GUI for user to sign up and I want to make it clear that user havent signed up before.I save all info in a Exel folder that I created with apache poi.It was working good until I add this Property.It doesnt write info to folder whether User signed up before or not.

and It doesn't throw Exception It works like nothing wrong


public void kullaniciGuncelle(String tc, String ad, String soyad, String musteri_no, String telefon, String hesap_turu)throws Exception{


    while (ayniVeriKontrol(tc,musteri_no)){
        fileInputStream = new FileInputStream("Test.xls");
        isimsiz_banka_verileri = new HSSFWorkbook(fileInputStream);

        musteri =isimsiz_banka_verileri.getSheetAt(0);
        sayac = 1 + musteri.getLastRowNum();
        row2 = musteri.createRow(sayac);
        celli = row2.createCell(0);
        celli.setCellValue(tc);
        celli = row2.createCell(1);
        celli.setCellValue(ad);
        celli = row2.createCell(2);
        celli.setCellValue(soyad);
        celli = row2.createCell(3);
        celli.setCellValue(musteri_no);
        celli = row2.createCell(4);
        celli.setCellValue(telefon);
        celli = row2.createCell(5);
        celli.setCellValue(hesap_turu);

        fileInputStream.close();

        fileOutputStream = new FileOutputStream("Test.xls");
        isimsiz_banka_verileri.write(fileOutputStream);
        isimsiz_banka_verileri.close();
        fileOutputStream.close();
    }


}

public boolean ayniVeriKontrol(String tc, String musteri_no) throws Exception{

    boolean kontrol = false;
    String geciciTc ,geciciNo;

    fileInputStream = new FileInputStream("Test.xls");
    isimsiz_banka_verileri = new HSSFWorkbook(fileInputStream);
    musteri = isimsiz_banka_verileri.getSheetAt(0);
    sayac = 1 + musteri.getLastRowNum();

    for (int i = 1; i < sayac; i++) {
        row2 = musteri.getRow(i);

        celli = row2.getCell(0);
        geciciTc = celli.getStringCellValue();

        celli = row2.getCell(3);
        geciciNo = celli.getStringCellValue();
        if (geciciTc == tc) {
            System.out.println("Ayılar");
            kontrol = true;
        }
    }

    fileInputStream.close();
    return kontrol;
}
FerhatA
  • 69
  • 1
  • 11
  • What do you mean by `It doesnt write info to folder`? Does it throw some exception? If yes, provide the stacktrace – Thiyagu Feb 25 '18 at 14:12
  • You should probably stop closing the stream in a loop. Just flush it, don't close until you're done with it – OneCricketeer Feb 25 '18 at 14:23
  • 1
    Your loop is never entered, actually... `geciciTc == tc`.... https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java and you might want to see [How to debug](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – OneCricketeer Feb 25 '18 at 14:24
  • @cricket_007 Thank you for how to debug.As a student It can help me to improve my self I changed while fo if else and ıt works now I will Update the post – FerhatA Feb 25 '18 at 14:48
  • @cricket_007 I edited Sorry for bad writing – FerhatA Feb 25 '18 at 14:51
  • @cricket_007 You can check the answer It works but You may have something to tell – FerhatA Feb 25 '18 at 14:53

1 Answers1

1

I changed while loop to if-else condition and now it writes and checks whether file has same user

    public void kullaniciGuncelle(String tc, String ad, String soyad, String musteri_no, String telefon, String hesap_turu)throws Exception{


    if (ayniVeriKontrol(tc,musteri_no)){
        fileInputStream = new FileInputStream("Test.xls");
        isimsiz_banka_verileri = new HSSFWorkbook(fileInputStream);

        musteri =isimsiz_banka_verileri.getSheetAt(0);
        sayac = 1 + musteri.getLastRowNum();
        row2 = musteri.createRow(sayac);
        celli = row2.createCell(0);
        celli.setCellValue(tc);
        celli = row2.createCell(1);
        celli.setCellValue(ad);
        celli = row2.createCell(2);
        celli.setCellValue(soyad);
        celli = row2.createCell(3);
        celli.setCellValue(musteri_no);
        celli = row2.createCell(4);
        celli.setCellValue(telefon);
        celli = row2.createCell(5);
        celli.setCellValue(hesap_turu);

        fileInputStream.close();

        fileOutputStream = new FileOutputStream("Test.xls");
        isimsiz_banka_verileri.write(fileOutputStream);
        isimsiz_banka_verileri.close();
        fileOutputStream.close();
    }
    else{
        KayitArayuzu kayit = new KayitArayuzu();
    }


}

public boolean ayniVeriKontrol(String tc, String musteri_no) throws Exception{

    boolean kontrol = true;
    String geciciTc ,geciciNo;

    fileInputStream = new FileInputStream("Test.xls");
    isimsiz_banka_verileri = new HSSFWorkbook(fileInputStream);
    musteri = isimsiz_banka_verileri.getSheetAt(0);
    sayac = 1 + musteri.getLastRowNum();

    for (int i = 1; i < sayac; i++) {
        row2 = musteri.getRow(i);

        celli = row2.getCell(0);
        geciciTc = celli.getStringCellValue();

        celli = row2.getCell(3);
        geciciNo = celli.getStringCellValue();
        if (geciciTc.equals(tc)) {
            System.out.println("Ayılar");
            kontrol = false;
        }
    }

    fileInputStream.close();
    return kontrol;
}
FerhatA
  • 69
  • 1
  • 11