简体   繁体   English

在存储过程中关闭连接

[英]Closing a connection in a stored procedure

In Apache Derby, stored procedures are java methods. 在Apache Derby中,存储过程是java方法。 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. Derby文档称为“嵌套连接”的这种类型的连接的全部要点是,它重新使用与导致其运行的语句相同的事务。

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. 实际上,一些在线Derby示例也关闭了连接。 That said, it's not being used in any transaction. 就是说,它没有在任何交易中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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