Google应用脚本错误“参数索引超出范围(1>参数数量,为0)”

时间:2018-08-30 09:55:30

标签: javascript sql jdbc google-apps-script

我知道此错误已被列出多次。我经历了所有前面的问题,并认为我的情况很独特。

我得到的错误是这个

  

参数索引超出范围(1>参数数量,即0)

这是唯一的,因为应该根据工作表中页眉的数量来调整脚本的插入值。

最后,没有对SQL服务器进行插入。

日志样本

[[3333096.0, LOADER, 05:30:22, 08/30/2018 05:30:22, 08/30/2018, ACCOUNT HAS BEEN SENT TO Agency STATSUS CHANGED FROM |originalstatus| TO |teststatus| ASSIGNEDTO CHANGE FROM |originalstatus| TO |testassigned| PORTFOLIO NAME: |PORTFOLIOX|],
[,  , , , , ],
[,  , , , , ],
[,  , , , , ],
[,  , , , , ],
[,  , , , , ],
[,  , , , , ],
[,  , , , , ],
[,  , , , , ],
[,  , , , , ]

Image of Sheet

function dboupdate() {
  var data = getData()  
  var headerstring = [1]  
  data = data[0]  
  try {
  
    var start = new Date();
    var conn = Jdbc.getConnection("X");   
  
    var sql = 'INSERT INTO ' + tablename + headerstring ;
    Logger.log(sql);
    var stmt = conn.prepareStatement(sql);

    for (var r in data) {
      Logger.log(data[r]);
      for (var c in data[r]) {
         stmt.setString(parseInt(c) +1 , data[r][c]);
      }
      stmt.addBatch();
    }
    var batch = stmt.executeBatch();
    conn.commit();
    conn.close();

    var end = new date();
 
  } catch (err) {
    SpreadsheetApp.getActive().toast(err.message);
    Logger.log(err.message);
  }
}

function getData(){
  var app = SpreadsheetApp;  
  // (filenumber,	collectorname,	logtime,	logdateandtime,	logdate,logmessage) VALUES (?,?,?,?,?,?)
  var ss = app.openById('X') ;  
  var importSheet = ss.getSheetByName('DBOlog');  
  var data = importSheet.getDataRange().getValues();
  var header = data[0];
  var headerstring = header.join(',')

  headerstring = '('+ headerstring + ') VALUES ('

  var questions = Array(header.length +1).join('?').split('')

  headerstring = headerstring + questions.join(',') + ')'
  Logger.log(headerstring)
  Logger.log(data.slice(1))
  return [data.slice(1), headerstring]
}  

0 个答案:

没有答案