Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我使用具有“自动提交关闭”的 JDBC 连接创建准备好的语句,我是否需要调用 commit() 以使事务永久化或仅准备调用就足够了?请注意,我只想准备一个语句并保留它以供以后执行。
非常感谢!
答案是:是的,你必须调用 commit。
“准备”步骤不做任何与服务器上的事务处理相关的事情。
您必须调用executeUpdate()(or execute()) 来启动事务(假设使用的 SQL 实际上确实启动了事务)
executeUpdate()
execute()
使用没有自动提交的 PreparedStatement 需要以下步骤:
Connection.commit()
为了让事情更清楚:调用prepareStatement()不需要.commit()
prepareStatement()
commit()