In OceanBase Database in Oracle mode, you can call Python APIs using OceanBase Connector/J to develop applications.
For more information about general Python APIs, see Python Database API Specification v2.0.
Create a test table in OceanBase Database and query the data in the table, as shown in the following sample code:
CREATE TABLE test_python(id NUMBER, name VARCHAR2(20));
INSERT INTO test_python VALUES (1, 'test1');
INSERT INTO test_python VALUES (2, 'test2');
COMMIT;
#!/usr/bin/env python3.6
# -*- coding: UTF-8 -*-
encoding = "utf8"
import jaydebeapi
def ob_test(): //ob_test() is a custom Python project name.
url = 'jdbc:oceanbase://host:port/database'
user = '**u***'
password = '**1***'
driver = 'com.alipay.oceanbase.jdbc.Driver'
jarFile = './oceanbase-client-2.2.3.jar'
sqlStr = 'select * from test_python' // SQL test statement
# conn=jaydebeapi.connect('oracle.jdbc.driver.OracleDriver','jdbc:oracle:thin:@10.0.0.0:1521/orcl',['hwf_model','hwf_model'],'E:/pycharm/lib/ojdbc14.jar')
conn = jaydebeapi.connect(driver, url, [user, password], jarFile)
curs = conn.cursor()
curs.execute(sqlStr)
result = curs.fetchall()
print(result)
curs.close()
conn.close()
ob_test()