I am new to Java and I've been studying it for a while now
I want to make a login program using excel to store the information.
The problem is that I don't know how to code the log in button.
I searched and came up with this code using iterator to find the values inside the XSSFSheet.
Can someone help me? Greatest Gratitude for those who will answer.
public void logInButtonPressed() {
try {
String user = userLogTF.getText();
String pass = passLogPF.getText();
FileInputStream inputStream = new FileInputStream(new File("Database.xlsx"));
Workbook workbook = WorkbookFactory.create(inputStream);
Sheet sheet = workbook.getSheetAt(0);
int i = 0;
boolean found = false;
Iterator<Row> rows = sheet.iterator();
while (rows.hasNext() || !found) {
XSSFRow row = (XSSFRow) rows.next();
XSSFCell cell = row.getCell(i++);
String userName = cell.toString();
Iterator<Cell> cellIterator = row.iterator();
if (userName.equals(user)) {
found = true;
} else {
i++;
}
while (cellIterator.hasNext()) {
Cell passCell = cellIterator.next();
String passWord = passCell.toString();
if (passWord.equals(pass)) {
JOptionPane.showMessageDialog(null, "Logged In");
break;
} else {
JOptionPane.showMessageDialog(null, "Invalid Input");
break;
}
}
}
} catch (Exception e) {
}
}
This is the excel file
This is the Gui

