2013-09-30 69 views
1

我有这样的Java代码,不幸被更新所做的更改不会被传播到MySQL数据库:更新预处理语句不commiting

  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; 

如果我启用了自动提交查询,确,作品;但手动提交不传播到数据库的变化(我手动检查,并没有更新作出选择*从schema.t1其中a不是空)。

任何想法可能发生在这里?

回答

0

尝试在提交后关闭prepared语句。因此,改变这种:

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

要这样:

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