当前位置: 首页 > news >正文

python: postgreSQL using psycopg2 or psycopg

psycopg2 

# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 許可資訊查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述: pip install --upgrade pip  PostgreSQL database adapter for Python
#  pip install psycopg2
# Author    : geovindu,Geovin Du 塗聚文.
# pip install pyqt6
# pip install pyside6
# pip install pyqt5
# IDE       : PyCharm 2023.1 python 3.11
# OS        : windows 10
# Datetime  : 2024/11/05 20:09
# User      : geovindu
# Product   : PyCharm
# Project   : PostgreSQL 9.6 PostgreSQL 9.6.24, compiled by Visual C++ build 1800, 64-bit
# File      : PostgreSQL.py
# explain   : 學習import psycopg2
import syscon = Nonetry:con = psycopg2.connect(database='TechnologyGame', user='postgres',password='888888',host='localhost', port='5432')cur = con.cursor()cur.execute('select * from School;')cur.fetchone()for record in cur:print(record)# 2#cur.execute('select version();')      #version = cur.fetchone()[0]#print(version)except psycopg2.DatabaseError as e:print(f'Error {e}')sys.exit(1)finally:if con:con.close()

psycopg 

# encoding: utf-8
# 版权所有 2024 ©涂聚文有限公司
# 許可資訊查看:言語成了邀功的功臣,還需要行爲每日來值班嗎?
# 描述: pip install --upgrade pip
#  pip install "psycopg[binary]"  https://github.com/psycopg/psycopg
# https://pypi.org/project/psycopg/
# Author    : geovindu,Geovin Du 塗聚文.
# pip install pyqt6
# pip install pyside6
# pip install pyqt5
# IDE       : PyCharm 2023.1 python 3.11
# OS        : windows 10
# Datetime  : 2024/11/05 20:09
# User      : geovindu
# Product   : PyCharm
# Project   : PostgreSQL 17.01 PostgreSQL 17.0 on x86_64-windows, compiled by msvc-19.41.34120, 64-bit
# File      : PostgreSQL.py
# explain   : 學習import psycopg  # pip install "psycopg[binary]"  https://github.com/psycopg/psycopg
from psycopg import pq
from psycopg.errors import DatabaseError
import sys
import oscon = Nonetry:# Connect to an existing database "dbname=TechnologyGame user=postgres password=888888 host=localhost port=5433"with psycopg.connect(" host=localhost port=5433 user=postgres password=888888 dbname=TechnologyGame") as conn:# Open a cursor to perform database operationswith conn.cursor() as cur:    # Query the database and obtain data as Python objects.cur.execute("SELECT * FROM School")cur.fetchone()   for record in cur:print(record)cur.execute('select version();')version = cur.fetchone()[0]print(version)# Make the changes to the database persistent#conn.commit()except DatabaseError as e:print(f'Error {e}')sys.exit(1)finally:if conn:conn.close()

http://www.lryc.cn/news/483371.html

相关文章:

  • 从 MySQL 5.7 到 8.0:理解 GROUP BY 的新规则与实战优化20241112
  • npm完整发包流程(亲测可验证)
  • 学习threejs,使用JSON格式保存和加载模型
  • 中国首部《能源法》正式问世,它的亮点有哪些呢?
  • 【外包】软件行业的原始形态,项目外包与独立开发者
  • 工程数学线性代数(同济第七版)附册课后习题答案PDF
  • 【Ubuntu24.04】部署服务(基础)
  • Linux符号使用记录
  • 初阶C++之C++入门基础
  • ODOO学习笔记(7):模块化架构(按需安装)
  • Java的dto,和多表的调用
  • 时序数据库TimescaleDB安装部署以及常见使用
  • MG算法(英文版)题解
  • 2-UML概念模型测试
  • 人工智能(AI)对于电商行业的变革和意义
  • 智能病历xml提取
  • RK3568平台开发系列讲解(GPIO篇)GPIO的sysfs调试手段
  • 使用 Web Search 插件扩展 GitHub Copilot 问答
  • workerman的安装与使用
  • QtQuick.Controls 控件介绍(都有哪些type)
  • Unity导出APK加速与导出失败总结(不定时更新)
  • 域名绑定服务器小白教程
  • 用 Collections.synchronizedSet 创建线程安全的 HashSet
  • 【深度学习】模型参数冻结:原理、应用与实践
  • 数字后端教程之Innovus report_property和get_property使用方法及应用案例
  • JS中console对象内部提供调试方法
  • python设计模式
  • 机器学习 笔记
  • 江协科技之STM32驱动1.3寸/0.96寸/0.91寸OLED显示屏介绍
  • Spring Security 认证流程,长话简说