久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Python psycopg2 沒有插入到 postgresql 表中

Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
本文介紹了Python psycopg2 沒有插入到 postgresql 表中的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在使用以下方法嘗試將記錄插入到 postgresql 數據庫表中,但它不起作用.我沒有收到任何錯誤,但表中沒有記錄.我需要提交還是什么?我正在使用通過 Bitnami djangostack 安裝的 postgresql 數據庫.

I'm using the following to try and insert a record into a postgresql database table, but it's not working. I don't get any errors, but there are no records in the table. Do I need a commit or something? I'm using the postgresql database that was installed with the Bitnami djangostack install.

import psycopg2

try:
    conn = psycopg2.connect("dbname='djangostack' user='bitnami' host='localhost' password='password'")
except:
    print "Cannot connect to db"

cur = conn.cursor()

try:
    cur.execute("""insert into cnet values ('r', 's', 'e', 'c', 'w', 's', 'i', 'd', 't')""")
except:
    print "Cannot insert"

推薦答案

如果不想每條記錄都提交到數據庫,可以添加以下行:

If don't want to have to commit each entry to the database, you can add the following line:

conn.autocommit = True

所以你得到的代碼是:

import psycopg2

try:
    conn = psycopg2.connect("dbname='djangostack' user='bitnami' host='localhost' password='password'")
    conn.autocommit = True
except:
    print "Cannot connect to db"

cur = conn.cursor()

try:
    cur.execute("""insert into cnet values ('r', 's', 'e', 'c', 'w', 's', 'i', 'd', 't')""")
except:
    print "Cannot insert"

這篇關于Python psycopg2 沒有插入到 postgresql 表中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動對象不可下標)
Insert element in Python list after every nth element(在每個第 n 個元素之后插入 Python 列表中的元素)
主站蜘蛛池模板: 麻豆国产一区二区三区四区 | 欧美日韩色 | 九九九热 | aaa亚洲| 国产精品综合 | 男男av| 久久久久久久成人 | 亚洲国产精品网站 | 日韩av在线免费播放 | 日本午夜网站 | 国产精品成人一区二区三区 | 酒色成人网 | 黄色成人毛片 | 亚洲三级黄色片 | 亚洲v视频 | 五月婷婷激情网 | 老司机免费福利视频 | 中文字幕在线观看亚洲 | av一区二区三区四区 | 欧美专区在线观看 | 亚洲乱码国产乱码精品精软件 | www.精品国产 | 黄色一级免费 | 欧美亚洲激情 | 成人免费视频观看视频 | 午夜小视频在线观看 | 国产精品久久久久久久久免费桃花 | 亚洲免费精品视频 | 亚洲国产精品自拍 | 中文天堂网 | 加勒比一区二区三区 | 欧美久久久久久久 | 天天操天天操天天 | 欧美va亚洲va | 丰满少妇高潮无套内谢 | 黄色片网站免费 | 青青草在线观看视频 | 日韩av在线不卡 | 国产中文字幕在线播放 | 天天干影院 | 中文字幕91|