CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Java application is taking long time compare than query browser to run the query.

  1. #1
    Join Date
    Nov 2010
    Posts
    2

    Java application is taking long time compare than query browser to run the query.

    Hi,
    I am getting big time difference when I run same query in query browser and in my application. The query browser it took only 2 seconds to run the query. But in my application it is taking 20 seconds.
    Actually, I am handling 12L records. I am using sql server database and used native SQL(JDBC) API in my application. I mean natve statement and resultSet API to fetch the record. I copied my code pieces here.

    //------------------------ COUNT QUERY ------------------------------------
    //It is taking 2 seconds in query browser but in my application takes 17 seconds
    try{
    String executeQry="select count(id) from temp where some condition";
    statement = m_jdbcConnection
    .prepareStatement(executeQry);
    resultSet = statement.executeQuery();
    while (resultSet.next()) {
    totalCount = resultSet.getInt(1);
    }
    } catch(Exception e){
    //
    }


    //------------------------ RESULTSET QUERY ------------------------------------
    //It is taking 2 seconds in query browser but in my application takes 20 seconds
    try{
    String executeQry="select ID,NAME,... from temp where some condition";// I used rownumber to limit.
    statement = m_jdbcConnection.prepareStatement(executeQry,ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    resultSet = statement.executeQuery();
    while (resultSet.next()) {
    //PROCESS THE RESULTSET
    }
    } catch(Exception e){
    //
    }

    Is there any mistake in my code to handle? or any logic I need to improve(Any Cache concept- Statement cache or ResultSet Cache).
    Please suggest me what are items I need to be care while handling large data(Java Level)

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,461

    Re: Java application is taking long time compare than query browser to run the query.

    What happens if you run the code more than once? Is it faster the second time?

  3. #3
    Join Date
    Nov 2010
    Posts
    2

    Re: Java application is taking long time compare than query browser to run the query.

    Quote Originally Posted by Arjay View Post
    What happens if you run the code more than once? Is it faster the second time?
    Thank for response. No, It is taking same time. Is there any cache concept in native JDBC?

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,461

    Re: Java application is taking long time compare than query browser to run the query.

    Quote Originally Posted by stsivaraj View Post
    Thank for response. No, It is taking same time. Is there any cache concept in native JDBC?
    Okay, I was wondering if it was the one time JIT compile or initial connection issue - usually if this was the case, the queries would be fast the second time.

    I'm out of my element with JDBC with regard to caching. If caching is desired, there might be a JDBC setting for caching (sorry, I don't know). If there isn't you can use another form of caching.

    Btw, have you checked to see if putting the SQL into a stored procedure speeds things up?

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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)