title: Google App Script - WRITE FROM GOOGLE SHEETS TO CLOUD SQL
body: <p>I'm trying to write data from a column in google sheets to a table in cloud sql.</p>
  <p>Error is:</p>
  <p>&quot;Exception: The parameters (String) don't match the method signature for Jdbc.JdbcPreparedStatement.setString.&quot;</p>
  <p>On line</p>
  <pre><code>stmt.setString('' + CopyData[i][0]);
  </code></pre>
  <p>I'm very new to google app script and have VERY limited knowledge of mySQL. Done a web development course in college about 10 years ago and havent looked at it since.</p>
  <p>The code I'm trying to use is:</p>
  <pre><code>function WriteToDB() {
  
    var connectionName = 'xxx';
    var user = 'xxx';
    var userPwd = 'xxx1';
    var db = 'TestDB';
    var instanceUrl = 'jdbc:google:mysql://' + connectionName;
    var dbUrl = instanceUrl + '/' + db;
    var conn = Jdbc.getCloudSqlConnection(dbUrl, user, userPwd);
        conn.setAutoCommit(false);
  
    var SS_File = SpreadsheetApp.getActiveSpreadsheet();
    var SourceSheet = SS_File.getSheetByName(&quot;WorkSheet1&quot;);
  
    var headerRowNumber = 1;
    var CopyData = SourceSheet.getDataRange().offset(headerRowNumber, 0, SourceSheet.getLastRow() - headerRowNumber).getValues();
  
   var stmt = conn.prepareStatement('INSERT INTO TestTable ' +  '(TestColumn) VALUES (?)');
  
   for (var i = 0; i &lt; CopyData.length; i++) {
    stmt.setString('' + CopyData[i][0]);
    stmt.addBatch();
  }
  
    var batch = stmt.executeBatch();
    conn.comit();
    conn.close();
  
    var end = new Date();
    Logger.log('Time elapsed: %s ms for %s rows.', end - start, batch.length);
  }
  </code></pre>
  <p>The connection is OK, I can create table etc through app script. Just can't write this data.</p>
  <p>The data is in column A on the spreadsheet, header row is 1.</p>
  <p>Can anyone help with this?</p>
  <p>Thanks!</p>
  <p>Ive tried</p>
  <pre><code> for (var i = 0; i &lt; CopyData.length; i++) {
    stmt.setObject(i, CopyData[i][0]);
    stmt.addBatch();
  </code></pre>
  <p>Error: &quot;Exception: Parameter index out of range (0 &lt; 1 )&quot;</p>
  <p>&amp;</p>
  <pre><code> for (var i = 0; i &lt; CopyData.length; i++) {
    stmt.setObject(i+1, CopyData[i][0]);
    stmt.addBatch();
  </code></pre>
  <p>Error: &quot;Exception: Parameter index out of range (2 &gt; number of parameters, which is 1)&quot;</p>
  <p>&amp;</p>
  <pre><code> for (var i = 0; i &lt; CopyData.length; i++) {
    stmt.setObject(i, CopyData[i]);
    stmt.addBatch();
  </code></pre>
  <p>Error: &quot;Exception: Invalid argument value: java.sql.SQLException&quot;</p>
  <p>Stuck.</p>