• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
allen cook
Greenhorn
Posts: 1
Java
  • Mark post as helpful
  • send pies
  • 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
 
Stephan van Hulst
Bartender
Pie
Posts: 6503
83
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 21554
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic