软件版本:
Python 3.10
MySQL 8.0
Python3 字典
v = {['v' : 'v']}
转换为 json 字符串
vv = json.dumps(v)
构造 sql 语句
sql = "INSERT INTO table_name (column_name) VALUES (%s)" % (vv)
写入 MySQL
db.query(sql)
报错信息:
"pymysql.err.ProgrammingError: (1064, '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 \'p1": [.................."
我理解应该是 json 数据没有没有转义造成的。
于是尝试
vv = ‘"""’ + vv ‘"""’
报同样的错误。
请问各位大佬有什么解决办法能直接将 json 数据写入 MySQL 吗?
Python 3.10
MySQL 8.0
Python3 字典
v = {['v' : 'v']}
转换为 json 字符串
vv = json.dumps(v)
构造 sql 语句
sql = "INSERT INTO table_name (column_name) VALUES (%s)" % (vv)
写入 MySQL
db.query(sql)
报错信息:
"pymysql.err.ProgrammingError: (1064, '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 \'p1": [.................."
我理解应该是 json 数据没有没有转义造成的。
于是尝试
vv = ‘"""’ + vv ‘"""’
报同样的错误。
请问各位大佬有什么解决办法能直接将 json 数据写入 MySQL 吗?