Connect an ODBC application to OceanBase Database (using Unix ODBC)

2023-07-21 09:10:58  Updated

This topic provides a code example on how to connect an ODBC application to OceanBase Database.

Procedure

Install dependencies

yum install unixODBC unixODBC-devel libtool-ltdl libtool-ltdl-devel
yum install mysql-connector-odbc -y

Check if the installation is successful

$odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/wangzelin.wzl/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8

$sudo vim /etc/odbcinst.ini

# Driver from the mysql-connector-odbc package
# Setup from the unixODBC package
[OceanBase]
Description     = ODBC for OceanBase
Driver64        = /usr/lib64/libmyodbc5.so
Setup64         = /usr/lib64/libodbcmyS.so
FileUsage       = 1

View configured drivers

$odbcinst -q -d
[PostgreSQL]
[MySQL]
[OceanBase]

Configure the data source

$sudo vim /etc/odbc.ini

[ob_db]
Description     = Data source OceanBase
Driver          = OceanBase
Server          = 127.0.0.1
Host            = 127.0.0.1
Database        = testdb
Port            = 2881
User            = r**t
Password        =
CHARSET         = UTF8

Check if the configuration is successful

$isql -v ob_db
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> show tables;
+-------------------------------------------------------------------------------+
| Tables_in_testdb                                                                                                                                                                                                                                                |
+-------------------------------------------------------------------------------+
| cities                                                                                                                                                                                                                                                          |
+-------------------------------------------------------------------------------+
SQLRowCount returns 1
1 rows fetched

Contact Us