Good day
I am still in school studying Java programming, and there is a project I have been working on. Everything has been working fine, however one feature of my program which allows the user to change their login credentials is no longer functioning properly. I don't recall changing anything and it worked fine before.
The problem occurs when I click the "Apply" button I have which executes a SQL query to change the username and password field values in a database. The JFrame freezes and I have to forcibly terminate it via WTM. Also to be noted is that in the console, I get a message in red saying:
Java Result: -805306369
It has that same value every time. I've done some Googling and all that I've found is that problems like the freezing are caused by looping errors, but to my knowledge I don't have any for this particular part of code.
If anyone could help me out I'd be so grateful! Pulling my hair out at this.
Below is my code for the "Apply" button, as well as the SQL query.
private void btnApplyActionPerformed(java.awt.event.ActionEvent evt) {
try {
if (txtNewUsername.equals("")) {
labelFlagUsername.setVisible(false);
JOptionPane.showMessageDialog(this, "You Need To Fill In The New Username Field", null, JOptionPane.ERROR_MESSAGE);
System.out.println("You Need To Fill In The New Username Field");
} else if (txtNewPassword.equals("")) {
labelFlagPassword.setVisible(false);
JOptionPane.showMessageDialog(this, "You Need To Fill In The New Password Field", null, JOptionPane.ERROR_MESSAGE);
System.out.println("You Need To Fill In The New Password Field");
} else {
UN = txtNewUsername.getText();//Gets value that user entered into field
PW = txtNewPassword.getText();//Gets value that user entered into field
DM.editLoginDetails(UN, PW);//Executes SQL query editLoginDetails
}
}
catch (Exception e)
{
JOptionPane.showMessageDialog(this, e.getMessage(), null, JOptionPane.ERROR_MESSAGE);
System.out.println(e.getMessage());
}
txtCurrentUsername.setText(" " + DM.getUsername(UN));
txtCurrentPassword.setText(" " + DM.getPassword(PW));
String temp = "";
txtNewPassword.setText(temp);
txtNewUsername.setText(temp);
}
SQL Query:
public String editLoginDetails(String UN, String PW)
{
try {
Statement st = con.createStatement();
String query = "UPDATE Users SET Username = '" + UN + "',Password = '" + PW + "';";
st.execute(query);
ResultSet rs = st.getResultSet();
JOptionPane.showMessageDialog(null, "Your login details were changed successfully!");
System.out.println("Your login details were changed successfully!");
catch (Exception e)
{
JOptionPane.showMessageDialog(null, e.getMessage());
System.out.println(e.getMessage());
}
return "Your login details were changed successfully!";
}
Finally, I thought it would be useful to know what this JFrame looked like. You'll get a better understanding of why my code is the way it is, hopefully.
I hope somebody can help me! Desperate to fix this annoying issue.