I am trying to select data from a table that has 4,630 records. Now, when I select this data from UNIX shell it takes less than a second, from JDBC it take good 3-4 seconds. Is such difference in execution time normal?
All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
I don't think that's normal, but perhaps not surprising as there's quite a lot going on. Try the following code to determine where the time is going:
You can also use the Unix time command to accurately time your query in Unix. I'm assuming that this is just test code, otherwise you should rewrite your query to use "SELECT COUNT(*)" Also, are you aware that you close the connection twice for each exception (catch & finally)?
Hope this helps.
Joined: Jan 24, 2001
I tried it, and it seems that results vary. One time it will take 4 sec, another 3 sec and sometimes 1 sec. And it all happens at execute(). Also, I close my connection twise if there is an exeption, I can't have finally() without catch() right?
Joined: Aug 02, 2004
Wrong. You can have either and you should have both. But only close the connection in the finally. You should be logging the exceptions in some way in the catch clauses.
Is there a network between your database and your Java process? That could be the cause of the variance. The speed of transfer will depend on the network bandwidth and load, and also how busy your DB server is. I'm not really sure what you can do about that. It might be worth putting it to the boys in the performance forum, but essentially I don't think it's Java performance.