使用Ruby将Json插入Mysql时出现日期时语法错误

时间:2015-03-01 15:23:05

标签: mysql ruby json datetime time

我有这样的JSON文件,

{
        "enter_date" : "2015-01-28",
        "enter_time" : "08:20:26"
    },
    {
        "enter_date" : "2015-01-28",
        "enter_time" : "08:30:25"
    },...

我使用Ruby从JSON文件获取数据,我尝试在合并为数据时之后将日期和时间插入到Mysql中。

data.each do |current|

    dt = Time.now.strftime(current["enter_date"] + " " + current["enter_time"])
    statement = "INSERT INTO doors (ent_time) values(#{dt})"
    results = client.query(statement);

end

我收到如下语法错误:Error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '08:20:26)' at line 1

我该如何解决这个问题?

0 个答案:

没有答案