If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > break off a DB2 cursor within a Java program

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-12-03, 06:09
hado2003 hado2003 is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
break off a DB2 cursor within a Java program

Hi all,

how can I break off a cursor for a DB2 database within a Java program ?
It should be possible at any time (during the open-time of the cursor or later).

Thanks in advance,
Hado
Reply With Quote
  #2 (permalink)  
Old 12-12-03, 10:32
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: break off a DB2 cursor within a Java program

Quote:
Originally posted by hado2003
Hi all,

how can I break off a cursor for a DB2 database within a Java program ?
It should be possible at any time (during the open-time of the cursor or later).

Could you please explain what you understand under "breaking off a cursor"?
Reply With Quote
  #3 (permalink)  
Old 12-12-03, 11:00
hado2003 hado2003 is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
Re: break off a DB2 cursor within a Java program

Quote:
Originally posted by n_i
Could you please explain what you understand under "breaking off a cursor"?
Ok, I'm reading a lot of rows from a DB2 database on the mainframe
in a table of my Java program. During the loading, sometimes I want break off this with ESC Key or Button.
Reply With Quote
  #4 (permalink)  
Old 12-12-03, 14:06
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: break off a DB2 cursor within a Java program

Quote:
Originally posted by hado2003
Ok, I'm reading a lot of rows from a DB2 database on the mainframe
in a table of my Java program. During the loading, sometimes I want break off this with ESC Key or Button.
If I understand you correctly you want to interrupt the query issued though JDBC.

The thread that issues Statement.executeQuery() blocks until the method returns, therefore it is not possible to interrupt it from within the same thread. You could probably attempt to close the corresponding Statement from another thread (that responds to a key or button event) but results could be unpredictable.

On the other hand, once the executeQuery() method returns there's nothing to interrupt. You can close ResultSet and then Statement at any moment.
Reply With Quote
  #5 (permalink)  
Old 12-15-03, 03:01
Bergerli Bergerli is offline
Registered User
 
Join Date: Dec 2003
Posts: 1
The problem with long running jdbc statements against the db2 os390 is the fact, that statement.cancel() operation is not supported.

Trying to cancel the statement within the same thread is obviously not possible as mentioned by n_i.

But even with a separate thread the call to the cancel()-method doesn't interrupt the query until you got a result set. Cancling the cursor is easy, just close.

Another problem occurs when we talk about SQLJ code.

So the following questions are still open:
+ how to cancel a long running SQLJ or JDBC statement.
+ is there a difference between (bound) SQLJ-code an JDBC code
+ is there a information source to give an overview on different RDBMS JDBC drivers according to the implementation of the optional operations e.g. cancel.


Here is some annotated SQLJ-generated test code to cancel a statement after 100 seconds. It won't work with DB2 OS/390 while it should according to the specification. (this is just code to test the core functions, its not production code)


synchronized (__sJT_execCtx) {
final sqlj****ntime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, DBAccess_SJProfileKeys.getKey(0), 11);
try
{
__sJT_stmt.setString(1, __sJT_1);
// define a simple watcher thread
Thread t = new Thread(new Runnable() {
public void run() {
try {
// wait 100 sec
Thread.currentThread().sleep(100000);
// try to cancel statement
__sJT_stmt.cancel();
System.err.println("cancling successfull");
} catch (InterruptedException e) {
} catch (SQLException e) {
log.error("SQLException", e);
}
}
});
t.start();
sqlj****ntime.profile.RTResultSet __sJT_result = __sJT_execCtx.executeQuery();
aenderungen = new AenderungenIter(__sJT_result);
}
finally
{
__sJT_execCtx.releaseStatement();
}
Reply With Quote
  #6 (permalink)  
Old 12-17-03, 12:13
hado2003 hado2003 is offline
Registered User
 
Join Date: Dec 2003
Posts: 4
How can I cancel a long running sqlj statement ?

How can I cancel a long running sqlj statement ?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On