python通过JayDeBeApi使用JDBC链接OceanBase

文章目录

    • 环境准备
      • 获取JayDeBeApi
      • 获取OceanBase JDBC驱动
      • OceanBase 集群搭建参见:
    • 测试验证

环境准备

获取JayDeBeApi

方法一:

pip install JayDeBeApi

方法二:

[admin@localhost ~]$ git clone https://github.com/baztian/jaydebeapi.git
Cloning into 'jaydebeapi'...
remote: Enumerating objects: 1710, done.
remote: Counting objects: 100% (123/123), done.
remote: Compressing objects: 100% (70/70), done.
remote: Total 1710 (delta 48), reused 90 (delta 27), pack-reused 1587
Receiving objects: 100% (1710/1710), 427.56 KiB | 452.00 KiB/s, done.
Resolving deltas: 100% (919/919), done.
[root@localhost jaydebeapi]# python3 setup.py install
running install
running bdist_egg
running egg_info
creating JayDeBeApi.egg-info
writing JayDeBeApi.egg-info/PKG-INFO
......

获取OceanBase JDBC驱动

https://help.aliyun.com/document_detail/212815.html

OceanBase 集群搭建参见:

手动部署 OceanBase 单节点

测试验证

[admin@localhost ~]$ python3.6
Python 3.6.13 (default, Feb 18 2022, 03:06:10)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jaydebeapi
>>> url = 'jdbc:oceanbase://l27.0.0.1:2881/test'
>>> user = 'root@sys'
>>> password = '123456'
>>> driver = 'com.alipay.oceanbase.jdbc.Driver'
>>> jarFile = './oceanbase-client-1.1.10.jar'
>>> sqlStr = 'select * from student'
>>> conn = jaydebeapi.connect(driver, url, [user, password], jarFile)
>>> curs = conn.cursor()
>>> curs.execute(sqlStr)
>>> result = curs.fetchall()
>>> print(result)
[(1, 'Aspirin', 'M'), (2, 'Taxol', 'F')]

你可能感兴趣的:(OceanBase,信创,python,数据库,OceanBase,信创)