Again i (=
As though authorization, i check on presence of record in db. Why that i do not receive the necessary result. Prompt in what a problem. Thankful in advance.
In db the table users a kind: |id|acc|pswd |...|
==================
public class DrugstoreFrame extends JFrame {
MsAcDatabase database;
Client person = new Client();
...
public void jButton3_mouseClicked(MouseEvent e) {
try{
database.findPersonAccPswd(getClientAcc());
if(person != null){
if(person.getPassword().equals(getClientPswd()))
{
cardLayout1.show(jPanel7, "jPanel4");
}
else {
pane.showMessageDialog(contentPane, "You have entered not the correct password !");
}
}
else{
pane.showMessageDialog(contentPane, "You haven't register!");
}
} catch(DataAccessException exception){
}
public String getClientAcc(){
String acc = getField(jTextField2);
return acc;
}
public String getClientPswd(){
String pswd = getField(jPasswordField1);
return pswd;
}
private String getField(JTextField field){
return field.getText();
}
...
}
========================
package drugstore;
public class MsAcDatabase implements ClientDataAccess{
private Connection connection;
private PreparedStatement sqlFindAccPswd;
....
public MsAcDatabase() throws Exception {
connect();
sqlFindAccPswd = connection.prepareStatement(
"SELECT acc FROM users WHERE acc = ? ");
}
public Client findPersonAccPswd(String account) throws DataAccessException {
try{
sqlFindAccPswd.setString(1, account);
ResultSet resultSet = sqlFindAccPswd.executeQuery();
if(!resultSet.next())
return null;
Client person = new Client();
person.setAccount(resultSet.getString(1));
person.setPassword(resultSet.getString(2));
return person;
} catch(SQLException sqlException) {
return null;
}
}
}
===============================
package drugstore;
public class Client {
private String account = "";
private String password = "";
...
public void setAccount(String account){
this.account = account;
}
public void setPassword(String password){
this.password = password;
}
}