質問

I have a long running select query on an embedded H2 Database and want to allow the user to cancel the query.

How can this be done? I cannot find anything about this.

[UPDATE] To be more specific I'm running my query using JPA. How can the query be stopped?

役に立ちましたか?

解決

H2 supports a query timeout setting. You can set this in the database URL as follows: jdbc:h2:~/db/test;query_timeout=10000. (Maybe this is not the right approach for you, but it might be for others that read this question.)

You can also cancel a query running in another connection (session) using the cancel_session function. But for this you need to enable the multi-threaded mode, which is currently not recommended for production use (it is still experimental in version 1.3.175).

他のヒント

If you have a few queries which might take very long, then don't use JPA for them. Create your own statement so you can cancel it.

Alternatively, get the source code for a JDBC proxy like log4jdbc and add code that allows you to get connections and statements per thread. That would allow you to get the statement after JPA has sent it to the proxy.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top