首页 > 解决方案 > 在 SQL 中使用批量更新时出现错误 MySQLNonTransientConnectionException

问题描述

以下鳕鱼:

String url;
ConnectionURL cURL= new ConnectionURL();
url=cURL.getCloudConnection();
try (Connection conn = DriverManager.getConnection(url))
{
    Statement statement = conn.createStatement();
    conn.setAutoCommit(false);

    for(int i=9;i<updateCformValues.size()-1;i++){
         List<Object> row=updateCformValues.get(i);
         String JDECode =(String)row.get(0);

        String CValue =(String)row.get(3);
        String updatedata = "update CRdataTable set OutstandingCFormValue='"+CValue+"'  where JDECode ='"+JDECode+"' ";
        log("String"+i);
        statement.addBatch(updatedata);
     }

    statement.executeBatch();


      conn.commit(); 
}

}
    catch (Exception e) {
            // TODO: handle exception
        out.print(e);
                e.printStackTrace();
        }

抛出异常

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed

请帮助我,谢谢。

标签: javamysqljdbc

解决方案


推荐阅读