Python连接GBase 8s数据库(通过ODBC)

Python连接GBase 8s数据库有多种方式,比如可以通过JDBC连接,这里介绍Python如何通过ODBC连接GBase 8s数据库。

1、配置GBase 8s数据库ODBC数据源

Python通过ODBC连接GBase 8s数据库,首先要进行ODBC数据源的配置,参考 GBase 8s ODBC数据源配置

2、Python环境安装pyodbc

pip install pyodbc

3、开始coding

import pyodbc

dsn = "DSN=gbaseserver1"
conn=pyodbc.connect(dsn)
cursor = conn.cursor()
# 执行个查询语句
cursor.execute("select * from emp")
rows = cursor.fetchall()
for row in rows:
    print(row)

你可能感兴趣的:(数据库,Python,数据库,python,database,odbc)