数据库
首页 > 数据库> > Python访问OceanBase数据库方法

Python访问OceanBase数据库方法

作者:互联网

操作步骤
1、安装jaydebeapi,操作方法:pip install jaydebeapi
2、将OceanBase Connector/J 的JAR安装包放入本地路径中,我使用的是oceanbase-client-2.2.7.jar,阿里提供的oceanbase-client-1.1.10.jar下载地址(https://oceanbase-aliyun-docs.oss-cn-hangzhou.aliyuncs.com/downloads/obclient/oceanbase-client-1.1.10.jar?spm=a2c4g.11186623.0.0.27aa4d5bho7Of4&file=oceanbase-client-1.1.10.jar)
3、测试程序如下:
import jaydebeapi
url = 'jdbc:oceanbase://host:port/database'   #ob数据库网址
user = 'userxxx@租户#集群'       #用户名,如配置有租户和集群,需要在此加上(很关键)   
password = 'passxxx'   #密码
driver = 'com.alipay.oceanbase.jdbc.Driver'
jarFile = './oceanbase-client-2.2.7.jar'
sqlStr = 'select * from test_python'     #SQL语句
conn = jaydebeapi.connect(driver, url, [user, password], jarFile)
curs = conn.cursor()
curs.execute(sqlStr)
result = curs.fetchall()
print(result)
curs.close()
conn.close()

标签:10,oceanbase,curs,Python,数据库,jar,OceanBase,client,1.1
来源: https://www.cnblogs.com/tywusy/p/15864602.html