• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How can I cancel a long running database background process in a Java Swing Program

 
Greenhorn
Posts: 1
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we cance/stop a long running database query execution instantly so that we can do any another task.

As i know swing uses a single thread i,e Event Dispatch Thread (EDT), But at the same time we can use Swingworker class for better use of UI. When we use Swingworker class the process goes to a different thread and our basic UI is not Frozen. Infact we can do another task. But what I want is I want to stop of cancel the execution of swingworker thread ( Because I that thread takes long time to execute). How can I do that??

I used ProgressMonitor and in the cancel option i canceled the task ( worker.cancel(true) also i closed the connection and statement for executing the database query using stmt.close() and conn.close() methods.
But it doesnot work.
Please write a sample code for me, How to cancel a long running database background process in a Java Swing Program.

Thank You
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Allen, welcome to CodeRanch!

Before we write *any* code, why don't you write code for us? Show us what you've tried.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would I be correct to assume that what you actually want to cancel is the database query? If so, then trying to stop the thread which is doing the query is not the right approach. You need something which stops the query itself. And that's a JDBC question (to which I don't know the answer). I will copy this thread to the JDBC forum to see if it might attract more attention there.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDBC itself doesn't provide ways to cancel JDBC calls, as far as I know. Some JDBC drivers, however, provide a database-specific methods to do so. For example, Oracle JDBC driver provides the OracleConnection.cancel() method. If you really want to do this, I'd suggest consulting your JDBC driver's documentation about the possibilities to cancel an operation. But you should also be aware that this makes your code database specific.
 
Grow a forest with seedballs and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic