DZone Forums
Go Back   DZone Forums > Community > Languages & Frameworks > Java
Reload this Page PreparedStatement slow down the query execution?
Notices
Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
Member
 
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Join Date: Feb 2008
Default PreparedStatement slow down the query execution? - 09-08-2008, 08:17 AM

Hi,

I got a problem during execute a sql.

I used the jdbc thin driver to connect to my oracle DB.

In my code, it looks like this

PreparedStatement oStmt = null;
oStmt = oCon.getConnection().prepareStatement(sQry, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);

if (!sMetaQuery.equals("")) {
oStmt.setString(1, StringUtils.toUpperCase(sMeta) + "%");
}

oStmt.setFetchSize(nMaxRows);
oStmt.setFetchDirection(ResultSet.FETCH_FORWARD);
oStmt.setString(1, sPartialKN);
oRS = oStmt.executeQuery();


The query is just something with join clause and some condition checks. when the program comes to call execute() method, it will take a quite long time (several minutes) to get the result. But when I directly run this query from some sql client it will only take several seconds.

Can some one help me to solve this probem?

Thanks and kind regards,

Hua
Reply With Quote
  (#2 (permalink)) Old
Forum Leader
 
glennji's Avatar
 
Posts: 58
Thanks: 0
Thanked 1 Time in 1 Post
Join Date: Feb 2008
Location: London
Send a message via MSN to glennji Send a message via Yahoo to glennji Send a message via Skype™ to glennji
Default 09-26-2008, 07:08 AM

Do multiple invocations of the query speed up?

A PreparedStatement is usually for a query that you're going to run a number of times -- it takes longer to "prepare", but then should be quicker to run.

Maybe time the prepareStatement() and the executeQuery() calls separately?
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Importing Environment variables before execution m_kk Eclipse 0 11-06-2008 10:55 AM
nobody has this problem? Slow down using RMI in Webstart? joco Java 0 09-23-2008 02:17 PM
Can any suggest regarding below my query shantcooldude Zones 0 07-08-2008 05:17 PM
IWAT4039E The Test Execution reported the following problems asha123 Eclipse 0 04-28-2008 02:13 AM
ant/eclipse/java 1.6.0_06 very slow dpm Eclipse 0 04-16-2008 03:07 AM


Copyright 1997-2009, DZone, Inc.
vBulletin Skin developed by: vBStyles.com