久久久久久久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 列表中的元素)
主站蜘蛛池模板: 国产激情一区二区三区 | av中文字幕在线 | 亚洲日日 | 亚洲国产精品一区二区第一页 | 日本精品久久久一区二区三区 | 日日爽| 日韩精品成人免费观看视频 | 亚洲福利一区二区 | 欧美国产91 | 日韩视频二区 | 在线国产视频 | 国产一区二区精品在线 | 欧美一级艳情片免费观看 | 国产午夜精品久久久 | 在线观看免费福利 | 精品一区二区电影 | 国产区在线免费观看 | 欧美日韩一 | 亚洲国产成人av好男人在线观看 | 第一区在线观看免费国语入口 | 日本a∨精品中文字幕在线 亚洲91视频 | 亚洲网站在线观看 | 日本一区二区在线视频 | а_天堂中文最新版地址 | 精品亚洲一区二区三区四区五区 | 亚洲一区二区三区在线免费观看 | 欧美亚洲第一区 | 中文在线一区二区 | 久久精品国产一区二区三区 | 日韩一区二区三区精品 | 中文字幕一二三 | 在线观看av网站永久 | 国产精品www | 99久久精品免费看国产四区 | 性色的免费视频 | 黄网免费| 日韩成人| 九九色九九 | 人成在线视频 | 精品久久香蕉国产线看观看亚洲 | 亚洲精品一区av在线播放 |