mercredi 1 février 2017

if statement is giving me an error that i can't understand in java [duplicate]

This question already has an answer here:

I've got this code:

private void jToggleButton1MouseClicked(java.awt.event.MouseEvent evt) {                                            
    Connection c = MysqlConnect.ConnectDB();
    PreparedStatement s = null;
    ResultSet rs = null;

    int N_Mec = Utilizador.N_Mec;
    JOptionPane.showMessageDialog(null, N_Mec);

    try{
        final String SQL = " Select Password from utilizador where N_Mec=" +N_Mec ;
        s = c.prepareStatement(SQL);
        rs = s.executeQuery();

        if(rs.next()){
        JOptionPane.showMessageDialog(null, "if" );
        String PassOrigem = Password_origem.getText();
        String password = rs.getString(1);
        JOptionPane.showMessageDialog(null, PassOrigem );
        JOptionPane.showMessageDialog(null, password );
        if(PassOrigem == password) {
            JOptionPane.showMessageDialog(null, "passei");
        } else {
            //JOptionPane.showMessageDialog(null, "deu merda");
        }
        //String Pass = Password.getText();
        //String PassNova = Password_Nova.getText();
        }

    } catch(Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }

the thing is: it sould compare a password that comes from database and a password that the user give. The variables "PassOrigem" and "password" are the same, i writted them and they are. But the programme doesn't enter in the if statement (it goes directly to the else statement). Help me please ps: sorry for my bad english and i'm learning the lenguage so if you see something dumb, don't kill me.

Aucun commentaire:

Enregistrer un commentaire