I had the same problem: CachedRowSetImpl.acceptChanges () does not disable autocommit, and when it switches to committing changes, an exception is thrown because they have already been executed individually.
Perhaps this is due to the fact that PostgreSQL is a bit picky about auto-negotiation. PostgreSQL does not allow you to disable autocommit through SQL queries (although this happened in the early days). Instead, any SQL statements that should be committed as a group should be sandwiched between the SQL BEGIN and COMMIT statements. The PostgreSQL JDBC driver supports Connection.setAutoCommit (false), but I bet it just motivates the driver to create BEGIN-COMMIT sandwiches behind the scenes. I assume that CachedRowSetImpl.acceptChanges () is trying to use SQL statements to disable autocommit instead of using setAutoCommit (false) and why it fails.
The only way to find this problem is to create a temporary connection, disconnect the autocommit, and transfer the connection with one version of acceptChanges. So instead:
crs.acceptChanges()
you will have something like this:
try (Connection con = DriverManager.getConnection(url, username, password)) { con.setAutoCommit(false); crs.acceptChanges(con); }
This requires using the Connection class, which you tried to avoid, but there can be no alternative (except for using JDBC). You cannot use CachedRowSetImpl.getConnection () because it only retrieves the connection that was created from the outside and then transferred. You cannot specify through the URL that you want the auto command to be disabled, since PostgreSQL does not allow this. It would be great if CachedRowSetImpl.acceptChanges () could be updated so that it automatically turns off auto-reporting. However, this seems unlikely as my compiler warns that CachedRowSetImpl may be removed in a future version.
source share