title: message: Remember that ordinal parameters are 1-based! (and I am)
body: <p>I'm trying to make a more generic method for a login.</p>
  
  <pre><code>public boolean login(String login, String pass) 
               throws ClassNotFoundException, SQLException {   
          open();   
          q = s.createQuery("select u from Usuario u 
                                 where u.login =:id1 and u.pass = :id2");   
          q.setString("id1", login);  
          q.setString("id2", pass);  
          if(q.uniqueResult()!=null)  
          return true;  
          else  
              return false;
  }
  </code></pre>
  
  <p>My code was working just fine but now I wanted to do something like:</p>
  
  <pre><code> public boolean login(String login, String pass) 
            throws ClassNotFoundException, SQLException {  
  
          return paramFunction("select u from Usuario u 
               where u.login = ?1 and u.pass=?2", login, pass);
   }
   public boolean paramFunction(String query, Object... params){
      try {
          open();
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
      } catch (SQLException e) {
          e.printStackTrace();
      }
      q = s.createQuery(query);
              for (int i = 1; i &lt;= params.length; i++) {
                  q.setParameter(i, params[i-1]);}
      if (q.uniqueResult() != null)
          return true;
      else
          return false;
  </code></pre>
  
  <p>but now I'm getting:   </p>
  
  <blockquote>
    <p>java.lang.IndexOutOfBoundsException: Remember that ordinal parameters
    are 1-based!</p>
  </blockquote>
  
  <p>although you can see I'm using a 1-based approach. What's wrong with what I'm doing?<br/><br/>
  Thanks for the help!</p>