如何从数据库中获取价值以与用户输入相匹配?

时间:2020-10-30 02:17:23

标签: java excel database apache-poi

我可以从Excel工作表中成功打印出用户名和密码,但是我无法将值与JTextField中的用户名输入和密码进行比较。 .equals()方法的逻辑对我也很有意义,因此我无法真正弄清问题所在。

任何帮助将不胜感激。谢谢!

submit.addActionListener(new ActionListener()
        
{
            
@Override
            
public void actionPerformed(ActionEvent e)
            
{
                
String uname = txtf1.getText().trim();
                
String pwd = txtf3.getText().trim();

try
                
{
                    
FileInputStream fis = new FileInputStream("database.xlsx");
                    
XSSFWorkbook wb= new XSSFWorkbook(fis);
                    
XSSFSheet sheet = wb.getSheetAt(0);
                    
XSSFRow row = sheet.getRow(0);
                    
XSSFCell cell = row.getCell(1);
                    
int starRow = sheet.getFirstRowNum();
                    
int endRow = sheet.getLastRowNum();
                    

for(int i = starRow + 1; i<50; i++)

{
                        
Cell c = wb.getSheetAt(0).getRow(i).getCell(1);
                        
String username = String.valueOf(c.getStringCellValue());
                        

                        
Cell c1 = wb.getSheetAt(0).getRow(i).getCell(3);
                        
String pwd1 = String.valueOf(c1.getStringCellValue());
                        

                        if(uname.equals(username)&&pwd.equals(pwd1))
                        {
                            Reviewer r1 = new Reviewer();
                            r1.setVisible(true);
                            r1.setSize(550,450);
                        }

                        
}

                    
                }

                catch(Exception error)
                {
                    error.printStackTrace();
                }           
            
            
            }

        });

Attached is a sample picture of how my excel looks like.

0 个答案:

没有答案