我正在尝试将记录写入 MySQL DB,其中我将表定义jobs
为:
CREATE TABLE jobs(
job_id INT NOT NULL AUTO_INCREMENT,
job_title VARCHAR(300) NOT NULL,
job_url VARCHAR(400) NOT NULL,
job_location VARCHAR(150),
job_salary_low DECIMAL(25) DEFAULT(0),
job_salary_high DECIMAL(25), DEFAULT(0),
company VARCHAR(150),
job_posted DATE,
PRIMARY KEY ( job_id )
);
我正在测试的代码是:
cur.execute("INSERT INTO jobs VALUES(DEFAULT, '"+jobTitle+"','"
+jobHref+"',"+salaryLow+","+salaryHigh+",'"+company+"',"
+jobPostedAdjusted+"','"+salaryCurrency+"';")
print(cur.fetchall())
我得到的错误是:
pydev debugger: starting
Traceback (most recent call last):
File "C:\Users\Me\AppData\Local\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013032300\pysrc\pydevd.py", line 1397, in <module>
debugger.run(setup['file'], None, None)
File "C:\Users\Me\AppData\Local\Aptana Studio 3\plugins\org.python.pydev_2.7.0.2013032300\pysrc\pydevd.py", line 1090, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "C:\Users\Me\Documents\Aptana Studio 3 Workspace\PythonScripts\PythonScripts\testFind.py", line 25, in <module>
+jobPostedAdjusted+"','"+salaryCurrency+"';")
TypeError: cannot concatenate 'str' and 'float' objects
插入此记录的最佳方法是什么?谢谢。