简体   繁体   English

从json文件将数据插入sqlite

[英]Insert data to sqlite from json file

What it's wrong here,i cant insert: 这是怎么回事,我无法插入:

 $.getJSON('file.json', function(data) {   

 tx.executeSql("INSERT INTO table (DATE, LIB, BID)  VALUES("+data.date+","+data.Lib+","+data.BID+")");

      });

You need quote the data you want to insert if they are string type. 如果它们是字符串类型,则需要引用要插入的数据。

"INSERT INTO table (DATE, LIB, BID)  VALUES('"+data.date+"','"+data.Lib+"','"+data.BID+"')"

And the below is better. 并且下面更好。

tx.executeSql("INSERT INTO table (DATE, LIB, BID)  VALUES(?,?,?)", [data.date, data.Lib, data.BID]));

i tried this code but it does not execute the query in the function(data) 我尝试了此代码,但未在函数(数据)中执行查询

kept the query before and after the function and it worked 在该函数之前和之后保留查询,并且可以正常工作

so had pass data to another function to execute the query 因此已经将数据传递给另一个函数来执行查询

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM