Exception: Argument too large: sql

107 views
Skip to first unread message

Carl-Johan Larsson

unread,
Aug 18, 2023, 3:27:54 PM8/18/23
to Google Apps Script Community
Hi all, I have a script that runs in Google Sheet, the script updates a MySQL db.

I get the error message: Exception: Argument too large: SQL.

Does anyone have any idea how I can bypass this?

function updateDB() {
  // clear range I6:I30 asnd K6:K30  //DONE
  SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(5, 10, 25, 1).clearContent();
  SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(5, 12, 25, 1).clearContent();
  // Get s some values
  var username = SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(2, 5).getValue();
  var database = SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(1, 5).getValue();

  var password = SpreadsheetApp.getUi().prompt("Password").getResponseText();

  var url = SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(3, 5).getValue();
  var dbUrl = "jdbc:mysql://" + url + ":3306/" + database;

  // Load the JDBC driver
  var conn = Jdbc.getConnection(dbUrl, username, password);
 
  // Loop to put multiple values
  for (var loop1 = 5; loop1 <= 29; loop1++) {

    // Update
    var stmt = conn.createStatement();
    var updateSql = SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(loop1, 9).getValue();
    var updateResult = stmt.executeUpdate(updateSql);

    // Put the result in the result cell
    SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(loop1, 10).setValue(stmt.getUpdateCount());

    // Close the statement
    stmt.close();
  }
  for (var loop2 = 5; loop2 <= 29; loop2++) {
    // Update
    var stmt = conn.createStatement();
    var updateSql = SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(loop2, 11).getValue();
    var updateResult = stmt.executeUpdate(updateSql);

    // Put the result in the result cell
    SpreadsheetApp.getActive().getSheetByName("Twig and HTML").getRange(loop2, 12).setValue(stmt.getUpdateCount());

    // Close the statement
    stmt.close();
  }
  // Close the connection
  conn.close();
}
Reply all
Reply to author
Forward
0 new messages