title: The index 2 is out of range
body: <pre><code>PreparedStatement preparedStatement = Connectionstring().prepareStatement(
              "Select Username from dbo.LoginDetails where Username = ? and Password =?");
    String User = tf_Fname.getText();
    String _Pass = new String(tf_Lname.getPassword());
          preparedStatement.setString(1, User);
          preparedStatement.setString(2, _Pass);
          ResultSet resultSet = preparedStatement.executeQuery();
          while (resultSet.next()) 
          {
              System.out.println("Username is "+ resultSet.getString(1)+"Password is "+resultSet.getString(2));  
          }
  </code></pre>
  
  <p>Without</p>
  
  <pre><code>+"Password is "+resultSet.getString(2)
  </code></pre>
  
  <p>it works fine, it is printing username from the database
  but with that it also throws an error.</p>
  
  <pre><code>com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range.
  </code></pre>