gpt4 book ai didi

java - 如何停止正在进行的 java.sql.statement.executeQuery()?

转载 作者:搜寻专家 更新时间:2023-10-30 20:26:46 24 4
gpt4 key购买 nike

我正在使用最新的 derby10.11.1.1。做这样的事情:

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

我得到异常 "java.sql.SQLFeatureNotSupportedException: Caused by: ERROR 0A000: Feature not implemented: cancel"

你知道是否有办法让它发挥作用吗?或者它真的没有在 Derby 中实现,我需要使用不同的嵌入式数据库吗?关于一些免费数据库的任何提示,我可以使用它代替 derby 并且支持 SQL 超时?

最佳答案

当我进入 java 文档时

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.

它会抛出

SQLFeatureNotSupportedException - 如果 JDBC 驱动程序不支持此方法

你可以使用 mysql。有这么多可用的嵌入式数据库,你可以通过 embedded database

关于java - 如何停止正在进行的 java.sql.statement.executeQuery()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30331580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com