从 Google 表格插入数据库时​​如何将空单元格值替换为 null

How can I replace empty cells value with null when inserting into database from Google Sheets

我正在尝试将电子表格数据插入 mysql 数据库。问题是 'CUSTOMER' 列中的某些单元格为空,这会在尝试 运行 代码时导致以下错误:

“不正确的整数值:第 1 行 'CLIENTE' 列的 ''”

我在准备查询时试图用 'null' 值替换空单元格,但我没有得到它。

感谢大家的帮助

谢谢

电子表格:

function writeManyRecords() {
  
    const conn = Jdbc.getConnection(dbUrl, user, userPwd);
    conn.setAutoCommit(false);
    const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    const sheet = spreadsheet.getSheetByName('FREEZERS');
    const data = sheet.getDataRange().getValues();
    const start = new Date();
    var stmt = conn.prepareStatement('INSERT INTO FREEZERS ' +  '(PATRIMONIO,DESCRICAO,CLIENTE,LOCAL_ESTOQUE,LOCAL_ANTERIOR_ESTOQUE) values (?, ?, ?, ?, ?)');
    for (var i = 1; i < data.length; i++) {
        stmt.setString(1,data[i][0]);
        stmt.setString(2,data[i][1]);
        if(!data[i][2] === '') {
            stmt.setString(3,data[i][2]);
        }
        stmt.setNull(3,4);
        stmt.setString(4,data[i][3]);
        stmt.setString(5,data[i][4]);
        stmt.addBatch();
        Logger.log('patrimonio: '+data[i][0]+'descricao: ' + data[i][1] +' cliente: '+ data[i][2])
    }

    const batch = stmt.executeBatch();
    conn.commit();
    conn.close();

    const end = new Date();
    Logger.log('Time elapsed: %sms for %s rows.', end - start, batch.length);
  } 

猜测:

if (!data[i][2] === '') { stmt.setString(3,data[i][2]) }
else { stmt.setNull(3,0) } // second number: 0 - null, 4 - integer, etc

How to use registerOutParameter in google script?