pyodbc 接口 1.环境 centos7 + x86_64
4.5.8.5
python3
2.安装pyodbc yum install -y gcc gcc-c++ unixODBC-devel python3 -m pip install pyodbc
3.配置odbc 修改配置文件cd /opt/highgo/hgdb-see-4.5.8/etc/drivers/ODBC/unixODBC/etc
,在odbcinst.ini
中添加以下内容:
Text [HighGoDriver] Description=HGDB driver for Linux Driver=/opt/highgo/hgdb-see-4.5.8/etc/drivers/ODBC/psqlODBC/lib/psqlodbcw.so Setup=/opt/highgo/hgdb-see-4.5.8/etc/drivers/ODBC/psqlODBC/lib/psqlodbcw.so UsageCount=1
配置环境变量export ODBCSYSINI=/opt/highgo/hgdb-see-4.5.8/etc/drivers/ODBC/unixODBC/etc
4.编写demo import pyodbcimport datetimetry : conn = pyodbc.connect('DRIVER={PostgreSQL Unicode(x64)};SERVER=192.168.168.159;port=5866;DATABASE=newnew;UID=sysdba;PWD=Hello@123' ) cursor = conn.cursor() cursor.execute("select count(*) as student_count from student" ) row = cursor.fetchone() print ("目前已有: " + str (row.student_count) + "条数据" ) cursor.execute("select * from student" ) rows = cursor.fetchall() print ("查询到:" + str (rows.__len__()) + "条数据" ) for row in rows: print (row.id , row.name) cursor.close() conn.close() except Exception as e: print (e)