Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Posts
    4

    Unanswered: 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

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: break off a DB2 cursor within a Java program

    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"?
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Dec 2003
    Posts
    4

    Re: break off a DB2 cursor within a Java program

    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.

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: break off a DB2 cursor within a Java program

    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.
    ---
    "It does not work" is not a valid problem statement.

  5. #5
    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.runtime.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.runtime.profile.RTResultSet __sJT_result = __sJT_execCtx.executeQuery();
    aenderungen = new AenderungenIter(__sJT_result);
    }
    finally
    {
    __sJT_execCtx.releaseStatement();
    }

  6. #6
    Join Date
    Dec 2003
    Posts
    4

    How can I cancel a long running sqlj statement ?

    How can I cancel a long running sqlj statement ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •