在这里我从文本字段中获取值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
2 回答
德玛西亚99
TA贡献1770条经验 获得超3个赞
您正在用空格声明密码。只需删除密码声明中的空格并尝试 .
String password = "";
for(int i = 0; i < passwordArray.length; i++){
password = password + passwordArray[i];
}
小唯快跑啊
TA贡献1863条经验 获得超2个赞
getRow() 方法检索当前行号,而不是行数。因此,在开始迭代 ResultSet 之前,getRow() 返回 0。
所以尝试这种方式。
resultSet.last();
total = resultSet.getRow();
resultSet.beforeFirst();
添加回答
举报
0/150
提交
取消