2013-09-30 70 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();