Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cancel database query....

 
Anu pama Dande
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a search screen developed in struts which results in different number of output records.

i want to make it user-friendly.

once user starts searching i want to show a cancel button on the page... n if query is taking more than a minute... then user should be able to cancel the query and start a new query.

my question is ... if user clicks on cancel button ... we can take him back to search screen and .. he can re-search but... the previous query will still be running on database side. How do I cancel that in action class?? n keep the database resources free from the previous query.

--Anupama
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Telling a query to stop running is no simple matter. The main problem is that when a query takes a long time to run, the overwhelming majority of that processing time is occuring on the database server, not in the application server. So, if you were to run a large JDBC query, the code would run very quickly until you got to:

ResultSet rs = statement.executeQuery();

at which time the JDBC code is waiting on the database server to execute the query and return a result.

You can use threading to run the query in the background. If you do this, you can certainly allow the user to cancel out of waiting to retrieve a result, but in my opinion, once a query is running, there isn't much point in trying to stop it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic