3

I am creating a simple JDBC connection and executing a prepared statement. The query returns 10 rows and it takes around 20 secs to execute the query in simple Java application.

When I deploy this as a WAR File in tomcat and the same query is executed by a servlet it takes around 3 to 4 minutes, sometimes more.

Not able to figure out the possible reason.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
  • 2
    Several places to look: 1) use a connection pool instead of opening the physical connection manually 2) make sure the latency between your application server and the database server is very low 3) check if both servers belong to the same network segment – Luiggi Mendoza Oct 05 '15 at 15:46
  • The problem is similar to this http://stackoverflow.com/questions/30775287/sql-execution-time-much-slower-in-a-tomcat-servlet-than-in-a-normal-java-program I am using a connection pool and yes both the servers belong to the same network and the Java Application and The server both are in same machine – Surendra Rathore Oct 05 '15 at 15:56

1 Answers1

2

It's been long. But if someone is still looking.

The root cause for the slowness was presence of a Join in the SQL. Although the join was faster in SQL Developer but I think when invoked from JDBC it was using a different and longer execution plan.

I splitted the join into two individual queries and it worked fine.