简体   繁体   中英

Closing a connection in a stored procedure

In Apache Derby, stored procedures are java methods. In those methods, I'm acquiring the connection using the following:

Connection conn = DriverManager.getConnection("jdbc:default:connection");

Should this be closed once we have finished using it?

No, typically it should not be closed in your stored procedure code.

The whole point of this type of connection, which the Derby documentation calls a "nested connection", is that it re-uses the same transaction as the statement that causes it to be run.

Closing the connection would mean that the invoking statement would have confusing behavior.

Just following up on this - there doesn't seem to be ill effects caused by closing the connection. In fact, some Derby examples online close the connection as well. That said, it's not being used in any transaction.

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