2

Can any one help with this issue that I'm having using prepared statements. The problem comes when trying to add the password to the statement which I am taking from a JPasswordField.

String Query = "SELECT * FROM Users WHERE Username = ? AND Password = ?";

PreparedStatement PrepedStatement = Con.prepareStatement(Query);

PrepedStatement.setString(1, Username.getText());
PrepedStatement.setString(2, Password.getPassword());
//It is no having any of this as getPassword() returns a Char[] which isn't a string

So does anyone have any ideas. Cheers.

Hewiiitt
  • 306
  • 1
  • 12

1 Answers1

1

This will likely work, however, I strongly consider noting Elliott Frisch's comment.

String has an overloaded constructor can take a character array as a parameter.

PrepedStatement.setString(2, new String(Password.getPassword()));

tier1
  • 6,303
  • 6
  • 44
  • 75