Announcement Announcement Module
Collapse
No announcement yet.
Which method is faster?QueryForRowSet or QueryForInt Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Which method is faster?QueryForRowSet or QueryForInt

    Hi,

    I am about to tune the performance of a method. The main purpose of the method is to get the number out from the query result.

    current implementation gets the number using
    SqlRowSet rs = JdbcOperations#queryForRowSet(sql, Object...), which returns a row contains a single column which has a integer value inside. Then a rs.getInt(1) is used to get the value.

    If I change it to queryForInt(sql, Object...) will that make a difference in terms of performance?

  • #2
    Post both method implementations to get a better idea and see clearly each difference

    but according to
    which returns a row contains a single column which has a integer value inside.
    since return a row with 1 column, and then I assume you could retrieve the value from the colum I could say the second approach is better since it return directly the value

    Check the API documentation for more details for each method

    Comment


    • #3
      Originally posted by dr_pompeii View Post
      Post both method implementations to get a better idea and see clearly each difference

      but according to

      since return a row with 1 column, and then I assume you could retrieve the value from the colum I could say the second approach is better since it return directly the value

      Check the API documentation for more details for each method
      As I said before the first implementation is:
      Code:
      public int someMethod(Object obj) {
        jdbcOperations.queryForRowSet(sql, new Object[] {obj});
        rs.next();
        return rs.getInt(1);
      }
      The second implementation is:

      Code:
      public int someMethod(Object obj) {
        return jdbcOperations.queryForInt(sql, new Object[] {obj});
      }

      Comment


      • #4
        Post your SQL query, but I could say the second approach

        try to avoid the new Object[] {obj}, I think could work only with obj

        Comment


        • #5
          The query is:

          Code:
          select count(id) from Table where foreignTableFK=?
          where foreignTableFK is an index.

          the Object obj is actually int obj that's why I need to use new Object[] {obj} here.

          Comment


          • #6
            Very strange. I have tested both methods in the project it seems queryForInt actually takes 1ms more time than queryForRowSet.

            Comment

            Working...
            X