将 psycopg2 连接到 PostgreSQL 方言数据库
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本页面介绍了如何将 PostgreSQL psycopg2 驱动程序连接到 PostgreSQL 方言数据库
。psycopg2
是 PostgreSQL 的 Python 驱动程序。
确保 PGAdapter 与
使用 PostgreSQL psycopg2 驱动程序进行连接的应用。
如需了解详情,请参阅启动 PGAdapter。
在 psycopg2
连接属性中,将 localhost
和 5432
指定为数据库服务器主机和端口。
- (可选)如果 PGAdapter 为
配置为在非默认 PostgreSQL 端口上进行监听
端口 (5432)。
- (可选)如果 PGAdapter 正在运行,请指定其他主机名
与本地机器位于不同主机上
connection = psycopg2.connect(database="database_name",
host="localhost",
port=5432)
cursor = connection.cursor()
cursor.execute('select \'Hello World\'')
for row in cursor:
print(row)
cursor.close()
connection.close()
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-09-26。
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]
{"lastModified": "\u6700\u540e\u66f4\u65b0\u65f6\u95f4 (UTC)\uff1a2024-09-26\u3002"}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-09-26。"]]