在这里我从文本字段中获取值
private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {
String userName = txtUserName.getText();
char[] passwordArray = txtPassword.getPassword();
String password = " ";
for(int i = 0; i < passwordArray.length; i++){
password = password + passwordArray[i];
}
int numberOfRecords = 0;
if(userName.equals("") || password.equals("")){
JOptionPane.showMessageDialog(this, "Please fill the form properly:");
}else{
System.out.println("i am here");
numberOfRecords = userServices.tryLogin(userName, password);
System.out.println("after number of records");
if(numberOfRecords == 1){
this.dispose();
mainForm.setVisible(true);
}else{
JOptionPane.showMessageDialog(this, "Sorry user name or password is incorrect:");
}
}
txtUserName.setText(" ");
txtPassword.setText("");
}
这是我的尝试登录方法
public int tryLogin(String userName, String password) {
int numberOfRecords = 0;
SQLQueryUtil sql = new SQLQueryUtil();
sql.connect(false);
String query = "SELECT COUNT(*) AS `number_of_records` FROM `user` "
+ "WHERE `userName`='" + userName + "' AND `password`='" + password + "';";
System.out.println(query);
ResultSet resultSet;
try{
resultSet = sql.executeQuery(query);
resultSet.isBeforeFirst();
numberOfRecords = resultSet.getRow();
System.out.println("number of Records =" + numberOfRecords);
} catch (Exception ex) {
ex.printStackTrace();
} finally{
sql.disconnect();
}
System.out.println("i am here also..............................");
return numberOfRecords;
}
当我点击登录按钮时,它显示以下结果驱动程序加载连接建立语句创建选择计数(*)number_of_records从user哪里userName=''和password='';记录数 =0
德玛西亚99
小唯快跑啊
相关分类