JDBC:更新表的最佳方法?

发布于 2024-08-03 03:11:41 字数 152 浏览 1 评论 0原文

假设我得到一个 ResultSet,它是使用来自 sql 数据库的联接进行查询的。

使用 sql 语句更新表或插入新元组/行更好吗?

或者我应该使用 resultSet.update() 函数?

我只想知道每种方法的缺点以及更新表的首选方法。

Let's say that I get a ResultSet which was queryed using joins from an sql database.

Is it better to use an sql statement to update the tables or insert new tuples/rows?

Or should i use the resultSet.update() function?

I just want to know the drawbacks associated with each as well as the preferred method of updating tables.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨小沫ゞ 2024-08-10 03:11:41

情况下才可更新:

  1. ResultSet 仅在以下 已使用适当的标志创建了语句 (ResultSet.CONCUR_UPDATABLE)
  2. 底层数据库/驱动程序支持对连接结果进行更新

如果两个条件都为真,则以这种方式完成更新可能会更有效,因为您已经将光标指向物品。否则,您将需要创建一个新语句 - 请务必为此使用PreparedStatement。

ResultSet will only be updatable if:

  1. You've created your statement with appropriate flag (ResultSet.CONCUR_UPDATABLE)
  2. The underlying database / driver supports updates over join results

If both conditions are true, updates are likely to be more efficient when done this way as you're already holding a cursor to the item. Otherwise you'll need to create a new statement - be sure to use a PreparedStatement for that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文