Win a copy of Pragmatic AI this week in the Artificial Intelligence forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Cancel database query....  RSS feed

 
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
 
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!