在Derby(JDBC)中提交之前,我可以关闭事务中的语句吗? [英] Can I close statements in a transaction before committing it in Derby (JDBC)?

查看:82
本文介绍了在Derby(JDBC)中提交之前,我可以关闭事务中的语句吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有(忽略异常处理等):

Basically I have (ignoring exception handling, etc.):

connection.setAutoCommit(false);

Statement statement1 = connection.createStatement();
statement1.executeUpdate("...");
statement1.close();

Statement statement2 = connection.createStatement();
statement2.executeUpdate("...");
statement2.close();

connection.commit();

如果我理解正确它不会产生任何影响,因为它所做的一切都是免费的资源GC。 特别是使用Derby :您应该在明确关闭语句,结果集和连接时你不再需要他们了。与Derby的连接是应用程序外部的资源,垃圾收集器不会自动关闭它们。

If I understand correctly it shouldn't have any impact because all it really does is free the resources for the GC. Especially with Derby: You should explicitly close Statements, ResultSets, and Connections when you no longer need them. Connections to Derby are resources external to an application, and the garbage collector will not close them automatically.

但是它会导致事务出现任何问题吗?我不相信交易依赖于声明。任何人都可以确认一下吗?

However will it cause any issues with the transaction? I don't believe the transaction relies on the Statement. Can anyone please confirm this?

推荐答案

当然,你可以关闭它们,你应该这样做。

Absolutely, you can close them, and you should.

这篇关于在Derby(JDBC)中提交之前,我可以关闭事务中的语句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆