1

我有这个 java 代码,不幸的是更新所做的更改没有传播到 mySQL 数据库:

            con = DriverManager.getConnection(url, user, password);
            con.setAutoCommit(false);
            preparedStatement = con.prepareStatement("update schema.t1 inner join 
                    schema.t2  on (t1.id=t2.id)" +
                   " set t1.a=t2.a, t1.b=t2.b" );


            int r = preparedStatement.executeUpdate();

            System.out.println("execute update result = "+r);
            preparedStatement.close();
            con.commit();
            con.close;

如果我启用自动提交查询,确实有效;但是手动提交不会将更改传播到数据库(我手动检查并且没有进行更新 select * from schema.t1 where a is not null)。

对这里可能发生的事情有任何想法吗?

4

1 回答 1

0

尝试在提交后关闭您的preparedStatement。所以改变这个:

preparedStatement.close();
con.commit();

对此:

con.commit();
preparedStatement.close();
于 2013-09-30T15:59:15.057 回答