简体   繁体   中英

Does Close method in Statement abort the request of DB also in JDBC

I wanted to know, does calling close method in Statement class also aborts the sql query in database, similar to how cancel method do?

By aborting a sql query, I mean sending something like HTTP DELETE request to the server to cancel a query.

Does something like this should also be done by close() method if in case application does not call cancel() method.

Close method in Statement class it is used to free up the resources used, this is because Connections to Derby are resources external to an application, and the garbage collector will not close them automatically. Note that a close method causes Derby to abort an in-flight transaction but a does NOT roll back the transaction.

You can see a detailed explanation in https://docs.oracle.com/javadb/10.8.3.0/devguide/cdevconcepts839085.html

Closing a statement closes the statement handle and should end and de-allocate any statement resources held by the database systems for that specific statement handle.

I'm not sure what you mean with 'abort', but if you attempt to close a statement while a method call of execute , executeQuery or executeUpdate is currently running, the behaviour is driver-dependent, but likely it will wait until that method call completes before it closes the statement. If you want to abort an in-progress statement execution, you should use Statement.cancel() .

If you attempt to close a statement while a result set is still open (that is executeQuery finished, but you haven't read or explicitly closed the result set), the result set will be closed, and any server-resources associated with that result set (eg a server-side cursor) will be closed as well. However, similar to an execute, if a fetch is in-progress (eg as part of a ResultSet.next() call), the close may wait until that fetch is complete, and use of Statement.cancel() may be necessary to abort such a fetch.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM