首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用nodejs将json数据插入到mysql表中

问如何使用nodejs将json数据插入到mysql表中
EN

Stack Overflow用户
提问于 2019-07-22 16:40:03
回答 1查看 53关注 0票数 0

ER_WRONG_VALUE_COUNT_ON_ROW:列计数与第1行的值计数不匹配

我在下面的代码中显示的是需要发送表的所有列。

代码语言:javascript
复制
  let rawdata = fs.readFileSync(uploadPath);
        try {
            student = JSON.parse(rawdata);
           // emp = student.employee;
           gstr2recon=student.cptyRecons;
           finPeriod=student.finPeriod;
      //console.log('gstr2recon',gstr2recon);

      jsonData['finperiod']=student['finperiod'];
      jsonData['cname']=student.cptyRecons['cname'];
      jsonData['total']=student.cptyRecons['totalCnt'];
      jsonData['matched']=student.cptyRecons['matchedCnt'];
      jsonData['mismatched']=student.cptyRecons['mismatchedCnt'];
      jsonData['onhold']=student.cptyRecons['onHoldCnt'];
      jsonData['pendinginasp']=student.cptyRecons['pendingCnt'];
      jsonData['availingstn']=student.cptyRecons['avlGstnCnt'];
      jsonData['email']=student.cptyRecons['cemail'];


           var database = mysql.createConnection({
            host:'192.168.1.1',
            port:'3306',
            user:'root',
            password:'password',
            database:'ui_support'
           });
           database.connect(function(connectionError){
            if(connectionError){
              throw connectionError;
            }
            console.log('jsonData',jsonData);
            var sql = "INSERT INTO gstr2Recon(finperiod,cname,ctin,total,matched,mismatched,onhold,pendinginasp,availingstn,email) VALUES ('" + jsonData + "')";
            database.query(sql, function(queryError, queryResult){
              if(queryError){
                throw queryError;
              }
            });
          });

我需要插入一些具有匹配json键值的列数据。

EN

回答 1

Stack Overflow用户

发布于 2019-07-23 14:58:09

它的打字错误

代码语言:javascript
复制
jsonData['finperiod']=student['finPeriod'];

请您在分配时遵循列名顺序和拼写错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57142132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档