add kinbase connect
This commit is contained in:
35
testConnectKingBase.py
Normal file
35
testConnectKingBase.py
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import psycopg2
|
||||||
|
from psycopg2 import sql
|
||||||
|
|
||||||
|
# 请根据实际情况修改以下参数
|
||||||
|
HOST = "192.168.1.28"
|
||||||
|
PORT = "54321"
|
||||||
|
DATABASE = "upp_demo"
|
||||||
|
USER = "system"
|
||||||
|
PASSWORD = "kingbase_ok"
|
||||||
|
|
||||||
|
try:
|
||||||
|
# 建立连接
|
||||||
|
conn = psycopg2.connect(
|
||||||
|
host=HOST,
|
||||||
|
port=PORT,
|
||||||
|
database=DATABASE,
|
||||||
|
user=USER,
|
||||||
|
password=PASSWORD
|
||||||
|
)
|
||||||
|
print("成功连接到人大金仓数据库!")
|
||||||
|
|
||||||
|
# 创建一个游标对象
|
||||||
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
# 测试执行简单SQL语句,如查询版本信息
|
||||||
|
cur.execute("SELECT version();")
|
||||||
|
version_info = cur.fetchone()
|
||||||
|
print("数据库版本信息:", version_info)
|
||||||
|
|
||||||
|
# 关闭游标和连接
|
||||||
|
cur.close()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
except psycopg2.Error as e:
|
||||||
|
print("连接失败:", e)
|
||||||
Reference in New Issue
Block a user