1

Is there any condition under which the following statement

PreparedStatement.executeQuery()

does not return or throw an exception?

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161
Rig Veda
  • 801
  • 2
  • 10
  • 17
  • 1
    I assume you mean, fails to throw an exception when it should? It won't throw an exception if it executed without error. – Peter Lawrey Jun 07 '09 at 07:01

2 Answers2

7

It depends on the database you're using and the configured isolation level. A common default is that a SELECT will block if you're trying to select records that have been updated in another transaction that hasn't committed yet.

Are you trying to select uncommitted data? What database are you using?

Alternatively your query may just be taking a really long time. Eliminate (or confirm) this possibility by running the query through some database tool.

You may also want to call setQueryTimeout() so the query won't block "forever".

cletus
  • 616,129
  • 168
  • 910
  • 942
  • OK, Is this applicable to update query as well ? Where can I find more details about it. – Rig Veda Jun 08 '09 at 06:49
  • @cletus: what happened if there is no running query and stops on this line "resultSet = preparedStatement.executeQuery()" ..?? – Bryan Jan 12 '12 at 07:22
  • Also make sure you're not using sqljdbc4.jar with Java 1.6.0_29, as they're incompatible: http://stackoverflow.com/questions/8986350/jdbc-connection-hangs-with-no-response-from-sql-server-2008-r2 – elyas-bhy Jun 10 '14 at 11:47
1

If it hasn't returned, then it's still running your query, or is still fetching the results.

Try running the query outside of java, using a database tool of some sort, and make sure it's executing in a timely fashion.

skaffman
  • 398,947
  • 96
  • 818
  • 769