Results 1 to 6 of 6

Thread: Which method is faster?QueryForRowSet or QueryForInt

  1. #1

    Default 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. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3

    Default

    Quote 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});
    }

  4. #4
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default

    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
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  5. #5

    Default

    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.

  6. #6

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •