H2 Database: Abort Query

守給你的承諾、 提交于 2019-12-12 19:24:31

问题


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?


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/21984515/h2-database-abort-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!