2

I'm using latest derby10.11.1.1. Doing something like this:

DriverManager.registerDriver(new org.apache.derby.jdbc.EmbeddedDriver())
java.sql.Connection connection = DriverManager.getConnection("jdbc:derby:filePath", ...)
Statement stmt = connection.createStatement();
stmt.setQueryTimeout(2); // shall stop query after 2 seconds but id does nothing
stmt.executeQuery(strSql);
stmt.cancel(); // this in fact would run in other thread

I get exception "java.sql.SQLFeatureNotSupportedException: Caused by: ERROR 0A000: Feature not implemented: cancel"

Do you know if there is way how to make it work? Or is it really not implemented in Derby and I would need to use different embedded database? Any tip for some free DB, which I can use instead of derby and which would support SQL timeout?

4
  • Please show your actual code, rather than "something like" it. It's difficult to diagnose the issue without the complete context. Please read "How to Ask" for additional details. Commented May 19, 2015 at 17:17
  • 2
    h2 supports a query timeout: stackoverflow.com/q/21984515/217324 Commented May 19, 2015 at 18:20
  • @DougR. my actual code is bit longer. What information are you missing? I'm afraid that Derby just does not support the cancel() at all. I found reference manual page where is written cancel() not supported by the server. So the questions remaining is how to un-lock derby query without cancel() or what else embedded database to use which can be cancel(). Commented May 19, 2015 at 18:25
  • So if it doesn't violate any NDA's, post your actual code, or a minimal, complete, and verifiable example that causes the error. Commented May 19, 2015 at 18:26

3 Answers 3

1

As i got in java docs

void cancel() throws SQLException
Cancels this Statement object if both the DBMS and driver support aborting an SQL statement. This method can be used by one thread to cancel a statement that is being executed by another thread.

and it will throws

SQLFeatureNotSupportedException - if the JDBC driver does not support this method

you can go with mysql. there are so many embedded database available you can go through embedded database

Sign up to request clarification or add additional context in comments.

4 Comments

it seems that mysql would require to install mysql server separately. There seems to be no free embedded mysql. Am I right? My goal is to have one jar including DB itself.
yes you need to install server for mysql then you need different database as in wikipedia en.wikipedia.org/wiki/Embedded_database
But they don't say whether cancel() would be supported or not :(. BTW is there other way than cancel() to kill the dead-locked transaction? Or am I doomed forever when this happens and I need to close whole app?
as nathan tolds h2 supports. you can go with that.
1

If you get Feature not implemented: cancel then that is definite, cancel is not supported.

From this post by H2's author it looks like H2 supports two ways to timeout your queries, both through the JDBC API and through a setting on the JDBC URL.

1 Comment

Yup works - in H2 table lock timeout is by default and changable by statement.execute("SET LOCK_TIMEOUT 5000");
0

Actually I found that there is deadlock timeout in derby as well only set to 60 seconds by default and I never have patience to reach it :).

So the correct answer would be:

stmt.setQueryTimeout(2); truly seems not working

stmt.cancel(); truly seems not implemented

But luckily timeout in database manager exists. And it is set to 60 seconds. See derby dead-locks.

Time can be changed using command:

statement.executeUpdate("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(" +
                "'derby.locks.waitTimeout', '5')");

And it works :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.