Postgresql 尝试将用户输入插入SQL表时出错
我遇到了一个问题,每当我尝试运行下面的代码并选择语句2以插入一个工具并输入一个随机工具名时,我都会收到错误消息:ProgrammingError('inserttool'列不存在\n第1行:插入工具(工具名,租赁天数)值(@inserttool,'2') 代码如下:Postgresql 尝试将用户输入插入SQL表时出错,postgresql,python-2.7,Postgresql,Python 2.7,我遇到了一个问题,每当我尝试运行下面的代码并选择语句2以插入一个工具并输入一个随机工具名时,我都会收到错误消息:ProgrammingError('inserttool'列不存在\n第1行:插入工具(工具名,租赁天数)值(@inserttool,'2') 代码如下: if Menu == "2": cursor = connection.cursor() InsertTool = raw_input("Please insert the tool that you want to add
if Menu == "2":
cursor = connection.cursor()
InsertTool = raw_input("Please insert the tool that you want to add.\n")
insert_tool = """insert into tools(tool_name, rental_days) values(@InsertTool, '2')"""
try:
cursor.execute( insert_tool);
connection.commit();
print("Tool is succesfully inserted!")
except Exception as e:
connection.rollback();
print("Exception Occured : ",e)
connection.close();
试试这个
if Menu == "2":
cursor = connection.cursor()
InsertTool = raw_input("Please insert the tool that you want to add.\n")
insert_tool = """insert into tools(tool_name, rental_days) values(%s, %s)"""
val = (InsertTool, "2")
try:
cursor.execute(insert_tool, val);
connection.commit();
print("Tool is succesfully inserted!")
except Exception as e:
connection.rollback();
print("Exception Occured : ",e)
connection.close();
非常感谢,现在它工作得非常好!我感谢您的帮助!:)