사용자 이름 또는 비밀번호 텍스트 상자가 비어 있지만 프로젝트를 실행할 때 "JOptionPane.showMessageDialog (null,"사용자 이름 또는 비밀번호가 잘못되었습니다. ")라는 텍스트 상자 만 표시되면 메시지 상자를 표시하려고합니다. ; " 제발 도와주세요 고마워요!비어있는 텍스트 상자 확인
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String user=txtUsername.getText();
char[] pass=txtPassword.getPassword();
if(user == null){
JOptionPane.showMessageDialog(null,"Username Field is empty");
}
else if(pass==null){
JOptionPane.showMessageDialog(null,"Password Field is empty");
}
else{
String sql="select * from account where username=? and password=?";
try{
pst=conn.prepareStatement(sql);
pst.setString(1,txtUsername.getText());
pst.setString(2,txtPassword.getText());
rs=pst.executeQuery();
if(rs.next()){
GridlockMain a=new GridlockMain();
a.setVisible(true);
}
else{
JOptionPane.showMessageDialog(null,"Your Username or Password is incorrect");
txtUsername.setText(null);
txtPassword.setText(null);
}
}
catch(SQLException e){
JOptionPane.showMessageDialog(null,e);
}
} }
나는 0 문자 미만의 문자열에 대해 들어 본 적이 없다. 그리고이 문제를 해결한다면이 답변은 대시의 [answer] (http://stackoverflow.com/a/20263060/369450)와 동일하므로이 대답을 무의미하게 만듭니다. – cpburnz