Statement cancelled due to timeout or client request

后端 未结 2 1701
生来不讨喜
生来不讨喜 2021-01-28 06:24

I am trying to add data to my Google Cloud SQL database using Google App Script. My code was working fine last night when I finished but when I ran it this morning it is now giv

相关标签:
2条回答
  • 2021-01-28 07:12

    Try it like this:

    function connection(folderId, db, c1, c2, c3, c4, c5, c6, c7) {
      var ss=SpreadsheetApp.openById("fileId");//just go to the file and get the id
      var sh=ss.getSheetByName('Report 1');
      var rg=sh.getRange("B5:H16");
      var sheetdata=rg.getValues();
      var conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);//dburl is not defined
      conn.setAutoCommit(false);
      var stmt = conn.prepareStatement('INSERT INTO '+ db + ' ' + '('+c1+','+c2+','+c3+','+c4+','+c5+','+c6+','+c7+') values (?, ?, ?, ?, ?, ?, ?)');
      for (var i=0; i<sheetdata.length; i++) {
        stmt.setString(1, Utilities.formatDate(sheetdata[i][0], Session.getScriptTimeZone(), 'yyyy-MM-dd'));
        stmt.setString(2, sheetdata[i][1]);
        stmt.setString(3, sheetdata[i][2]);
        stmt.setString(4, sheetdata[i][3]);
        stmt.setString(5, sheetdata[i][4]);
        stmt.setString(6, sheetdata[i][5]);
        stmt.setString(7, sheetdata[i][6]);
        stmt.addBatch();   
      }
      var batch = stmt.executeBatch();
      conn.commit();
      conn.close();
    }
    
    0 讨论(0)
  • 2021-01-28 07:17

    Found out that the issue is with the new App Script Runtime V8. For a fix, change your runtime back to Rhino. To do this go to "View > Show project manifest" then where it says "runtimeVersion": "V8" change this to be "runtimeVersion": "STABLE". There is currently an open bug on this issue here: https://issuetracker.google.com/issues/149413841

    0 讨论(0)
提交回复
热议问题