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()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM