-
March 17th, 2016, 10:52 AM
#1
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)
-
March 17th, 2016, 12:41 PM
#2
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?
-
March 21st, 2016, 01:17 AM
#3
Re: Java application is taking long time compare than query browser to run the query.
Originally Posted by Arjay
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?
-
March 21st, 2016, 12:39 PM
#4
Re: Java application is taking long time compare than query browser to run the query.
Originally Posted by stsivaraj
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|