Why my sql doesn't execute?
I have a python script that needs to update a database information. So, in my init() method, I start the connection. But when I call the update method, the script does not give me any answer, it seems like it is into an infinite loop.
def update(self,id,newDescription):
try:
sql="""UPDATE table SET table.new_string=:1 WHERE table.id=:2"""
开发者_如何学Python con=self.connection.cursor()
con.execute(sql,(newDescription,id))
con.close()
except Exception,e:
self.errors+=[str(e)]
What I've tried so far:
- Change the query, just to see if the connection is alright. When I did that (I used 'SELECT info from table'), the script worked.
- I thought that my query was wrong, but when I execute it in SQLDeveloper program, it goes right.
What can be happening?
Thanks
You are forgetting to call commit
.
Not sure about how to do it in python script, but i think you need to call a "commit" before closing connection. Otherwise oracle rollsback your transaction.
Try adding con.commit() before close()
精彩评论