title: Problem connecting a login method in my Java program to MySQL table using JDBC
body: <p>I'm writing a Java program (with Java Swing and JDBC) and in one of my panels, I have a login. I want my program to compare the entered username and password and compare it to the ones U have in my database table (MySQL). This is what I wrote in my &quot;Login&quot; button, see for yourself:</p>
  <pre><code>try {
      Class.forName(&quot;com.mysql.jdbc.Driver&quot;).newInstance();
      String url2 = &quot;jdbc:mysql://localhost:3306/Students?user=root&quot;;
      Connection connect2 = DriverManager.getConnection(url2);
      Statement state2 = connect2.createStatement();
      String query2 = &quot;select * from login_data where username='%s'&quot;;
      query2 = String.format(query2,username1.getText());
      ResultSet result2 = state2.executeQuery(query2);
      if(result2.next()){
          if(result2.getString(&quot;password&quot;)==password1.getText()){
              login.setVisible(false);
              Mainmenu();
          }else{
              result1.setText(&quot;Wrong Password&quot;);
          }
      }else{
          result1.setText(&quot;Wrong Username!!!&quot;);
      }
  
      state2.close();
      connect2.close();
  
  } catch (SQLException e1) {
      e1.printStackTrace();
  } catch (IllegalAccessException e1) {
      e1.printStackTrace();
  } catch (InstantiationException e1) {
      e1.printStackTrace();
  } catch (ClassNotFoundException e1) {
      e1.printStackTrace();
  }
  </code></pre>
  <p>Now, if I give it a wrong username, it correctly shows the &quot;wrong username&quot; message. However, if the username is correct, it shows the &quot;wrong password&quot; message. It doesn't matter if the password is/isn't correct.</p>
  <p>I feel there is a logical error here, but I can't see it.</p>