views:

54

answers:

2

I am trying to execute a query in oracle db. When i try to run thru SQLTools the query is executing in 2 seconds and when i run the same query thru JAVA it is exectuting in more than a minute.

I am using a hint /*+ordered use_nl (a, b)*/

I am using ojdbc6.jar Is it because of any JARS? Please help whats causing this?

+1  A: 

For Oracle 9i or later, database engine can tune SQL automatically, few case need to specify hints.

How do you run query in Java, repeat to run in loop? use parameter? prepare before execute?

shiki
I am running thru preparedstatement
Do you measure one minute time in which statement?1. preparestatement()2. execute()3. while (resultSet.next())4. // do somethingcost one minute in which step?
shiki
A: 

You need to profile your Java application to identify where in the Java code before or after the SQL execution that overhead time is being spent.

Some profiling tools that you can use for that are: YourKit, JProfiler and HPROF (this one is a command line tool).

Bruno Rothgiesser
Why was my answer downvoted? You really need to run a profiler to find out why it takes a minute to run the SQL via your Java app. I doubt that it is in Oracle that it is taking over a minute, since it only takes 2 seconds from SQL Tools.
Bruno Rothgiesser