开发者

INSERT not working in cx_oracle when used with execute. How to get it working?

I am new to cx_oracle. I have established a connection and I am able to create and drop a ta开发者_如何学运维ble using execute.

Where I am failing is when I try to use "INSERT INTO ..." in execute. It doesn't show any error but it doesn't store any value either (I confirmed this by checking if the entry had taken place using sqlplus from shell). The code I used was:

table_name = "T1"
column = "D"
insert_value = "test value"

sqlcode = "INSERT INTO "+table_name+" ("+column+") VALUES ('"+insert_value+"')"
cursor.execute(sqlcode)

Please help me, any help would be appreciated.

Thanks in advance. J


How can cursor.commit work when the methods in Cursor do not have commit, connections has this method and hence it should be:

    connection.commit()

Using cursor.commit() returns:
AttributeError: 'cx_Oracle.Cursor' object has no attribute 'commit'


Strange that you are not getting an error with that code; that's of course unless you are (sadly) calling the Cursor object, connect.

You need to have something like this somewhere, before all your code:

conn = cx_Oracle.connect(usr, pwd, url)
cursor = conn.cursor()

Proceed then to replace connect.execute(sqlcode) with cursor.execute(sqlcode).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜