OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Resources

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS

OceanBase Cloud

OceanBase Database

Tools

Connectors and Middleware

QUICK START

OceanBase Cloud

OceanBase Database

BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Company

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

International - English
中国站 - 简体中文
日本 - 日本語
Sign In
Start on Cloud

A unified distributed database ready for your transactional, analytical, and AI workloads.

DEPLOY YOUR WAY

OceanBase Cloud

The best way to deploy and scale OceanBase

OceanBase Enterprise

Run and manage OceanBase on your infra

TRY OPEN SOURCE

OceanBase Community Edition

The free, open-source distributed database

OceanBase seekdb

Open source AI native search database

Customer Stories

Real-world success stories from enterprises across diverse industries.

View All
BY USE CASES

Mission-Critical Transactions

Global & Multicloud Application

Elastic Scaling for Peak Traffic

Real-time Analytics

Active Geo-redundancy

Database Consolidation

Comprehensive knowledge hub for OceanBase.

Blog

Live Demos

Training & Certification

Documentation

Official technical guides, tutorials, API references, and manuals for all OceanBase products.

View All
PRODUCTS
OceanBase CloudOceanBase Database
ToolsConnectors and Middleware
QUICK START
OceanBase CloudOceanBase Database
BEST PRACTICES

Practical guides for utilizing OceanBase more effectively and conveniently

Learn more about OceanBase – our company, partnerships, and trust and security initiatives.

About OceanBase

Partner

Trust Center

Contact Us

Start on Cloud
编组
All Products
    • Databases
    • iconOceanBase Database
    • iconOceanBase Cloud
    • iconOceanBase Tugraph
    • iconInteractive Tutorials
    • iconOceanBase Best Practices
    • Tools
    • iconOceanBase Cloud Platform
    • iconOceanBase Migration Service
    • iconOceanBase Developer Center
    • iconOceanBase Migration Assessment
    • iconOceanBase Admin Tool
    • iconOceanBase Loader and Dumper
    • iconOceanBase Deployer
    • iconKubernetes operator for OceanBase
    • iconOceanBase Diagnostic Tool
    • iconOceanBase Binlog Service
    • Connectors and Middleware
    • iconOceanBase Database Proxy
    • iconEmbedded SQL in C for OceanBase
    • iconOceanBase Call Interface
    • iconOceanBase Connector/C
    • iconOceanBase Connector/J
    • iconOceanBase Connector/ODBC
    • iconOceanBase Connector/NET
icon

OceanBase Connector/ODBC

V2.0.9

  • Overview
  • Driver installation and configuration
    • Prepare for the installation
    • Install and configure the ODBC driver for Linux
    • Install and configure OceanBase Connector/ODBC for Windows
  • User guide
    • Basic operations
    • Enable logging
    • Get REF CURSOR data type
    • Scalar function escape
    • Call Function
  • Reference information
    • API functions in OceanBase Connector/ODBC
    • Data types in OceanBase Connector/ODBC
    • Error codes in OceanBase Connector/ODBC
  • FAQ
    • Query timeout
    • Chinese garbled characters
    • Common OceanBase ODBC installation and configuration issues and solutions
  • 600.version-release-records
    • 9900.V2.0
      • OceanBase Connector/ODBC V2.0.9
      • OceanBase Connector/ODBC V2.0.8
      • OceanBase Connector/ODBC V2.0.7
      • OceanBase Connector/ODBC V2.0.6

Download PDF

Overview Prepare for the installation Install and configure the ODBC driver for Linux Install and configure OceanBase Connector/ODBC for Windows Basic operations Enable logging Get REF CURSOR data type Scalar function escape Call Function API functions in OceanBase Connector/ODBC Data types in OceanBase Connector/ODBC Error codes in OceanBase Connector/ODBC Query timeout Chinese garbled characters Common OceanBase ODBC installation and configuration issues and solutions OceanBase Connector/ODBC V2.0.9 OceanBase Connector/ODBC V2.0.8 OceanBase Connector/ODBC V2.0.7 OceanBase Connector/ODBC V2.0.6
OceanBase logo

The Unified Distributed Database for the AI Era.

Follow Us
Products
OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
Resources
DocsBlogLive DemosTraining & Certification
Company
About OceanBaseTrust CenterLegalPartnerContact Us
Follow Us

© OceanBase 2026. All rights reserved

Cloud Service AgreementPrivacy PolicySecurity
Contact Us
Document Feedback
  1. Documentation Center
  2. OceanBase Connector/ODBC
  3. V2.0.9
iconOceanBase Connector/ODBC
V 2.0.9
  • V 2.0.9
  • V 2.0.8
  • V 2.0.7
  • V 2.0.6

Install and configure OceanBase Connector/ODBC for Windows

Last Updated:2026-04-10 07:06:59  Updated
share
What is on this page
Install OceanBase Connector/ODBC
Configure a data source
Connection examples
Example 1: Add a data source (for OceanBase Database in Oracle mode)
Example 2: Install OceanBase Connector/ODBC without adding a data source (which will be specified in the code)

folded

share

Install OceanBase Connector/ODBC

After you obtain the installation packages of OceanBase Connector/ODBC for Windows, perform the following operations to install and configure OceanBase Connector/ODBC.

Configure a data source

  1. Follow the default instructions to install OceanBase Connector/ODBC for Windows.
  2. Choose Control Panel > System and Security > Administrative Tools > ODBC Data Sources > Drivers. The OceanBase Connector/ODBC driver is displayed on this tab.

win-configure-data-source-1.png

  1. Double-click the driver. Choose User DSN > Add. Select the driver, and click Finish.

Win-DSN1.png

  1. In the dialog box that appears, specify Name and Description, and click Next.

Win-DSN2.png

  1. Specify database connection information, and click Next. In the dialog box that appears, specify the initialization statement, TLS, cursor, and result set as needed.

Win-DSN3.png

  1. Click Finish. The data source is added. Then click OK.

Win-DSN4.png

Connection examples

Example 1: Add a data source (for OceanBase Database in Oracle mode)

#include<stdio.h>
#include<assert.h>
#include<windows.h>
#include<sql.h>
#include<sqlext.h>

static void odbc_print_error(SQLSMALLINT HandleType, SQLHANDLE Handle)
{
  SQLCHAR SQLState[6];
  SQLINTEGER NativeError;
  SQLCHAR SQLMessage[SQL_MAX_MESSAGE_LENGTH] = { 0 };
  SQLSMALLINT TextLengthPtr;

  SQLGetDiagRec(HandleType, Handle, 1, SQLState, &NativeError, SQLMessage, SQL_MAX_MESSAGE_LENGTH, &TextLengthPtr);
  fprintf(stdout, "[%s] (%d) %s\n", SQLState, NativeError, SQLMessage);
}

static void ASSERT_CHECK(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLRETURN rcode)
{
  if(rcode != SQL_SUCCESS && rcode != SQL_SUCCESS_WITH_INFO){
    odbc_print_error(HandleType, Handle);
    assert(0);
  }
}

int main()
{
  HENV henv;
  SQLCHAR OutConnStr[255];
  SQLSMALLINT OutConnStrLen;

  // Apply for an environment handle.
  SQLRETURN rcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
  ASSERT_CHECK(SQL_HANDLE_ENV, henv, rcode);

  // Set the environment attributes of the ODBC version.
  rcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0);
  ASSERT_CHECK(SQL_HANDLE_ENV, henv, rcode);

  // Allocate a connection handle.
  SQLHDBC hdbc; rcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
  ASSERT_CHECK(SQL_HANDLE_DBC, hdbc, rcode);

  // Connect to the data source.
  //char* mydriver = (char*)"Driver={OceanBase ODBC 2.0 Driver};Server=xxx.xxx.xxx.xxx;Port=38884;Database=test;User=xxx@oracle;Password=xxx;Option=3;";
  //rcode = SQLDriverConnect(hdbc, NULL, (SQLCHAR*)mydriver, strlen((char*)mydriver) + 1, OutConnStr, 255, &OutConnStrLen, SQL_DRIVER_NOPROMPT);
  rcode = SQLConnect(hdbc, (SQLCHAR *)"oboracle", SQL_NTS, (SQLCHAR *)"test@oracle", SQL_NTS, (SQLCHAR *)"test", SQL_NTS);
  ASSERT_CHECK(SQL_HANDLE_DBC, hdbc, rcode);

  // Create an SQL statement handle.
  SQLHSTMT stmt;
  rcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &stmt);
  ASSERT_CHECK(SQL_HANDLE_STMT, stmt, rcode);

  // Execute the SQL statement.
  rcode = SQLExecDirect(stmt, (SQLCHAR*)"select 1, 'obodbc', 88 from dual", SQL_NTS);
  ASSERT_CHECK(SQL_HANDLE_STMT, stmt, rcode);

  // Bind and obtain data items.
  SQLINTEGER res = SQL_NTS;
  SQLCHAR name[128];
  SQLINTEGER age;
  SQLBindCol(stmt, 2, SQL_C_CHAR, name, sizeof(name), &res);
  SQLBindCol(stmt, 3, SQL_C_SLONG, &age, sizeof(age), &res);
  while ((rcode = SQLFetch(stmt)) != SQL_NO_DATA_FOUND)
  {
    if (rcode == SQL_ERROR) {
      printf("sql error!\n");
    } else {
      printf("name:%s, age:%ld\n", name, age);
    }
  }

  // Release resource handles.
  SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  SQLDisconnect(hdbc);
  SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
  SQLFreeHandle(SQL_HANDLE_ENV, henv);
  return 0;
}

Example 2: Install OceanBase Connector/ODBC without adding a data source (which will be specified in the code)

#include<stdio.h>
#include<assert.h>
#include<windows.h>
#include<sql.h>
#include<sqlext.h>

static void odbc_print_error(SQLSMALLINT HandleType, SQLHANDLE Handle)
{
  SQLCHAR SQLState[6];
  SQLINTEGER NativeError;
  SQLCHAR SQLMessage[SQL_MAX_MESSAGE_LENGTH] = { 0 };
  SQLSMALLINT TextLengthPtr;

  SQLGetDiagRec(HandleType, Handle, 1, SQLState, &NativeError, SQLMessage, SQL_MAX_MESSAGE_LENGTH, &TextLengthPtr);
  fprintf(stdout, "[%s] (%d) %s\n", SQLState, NativeError, SQLMessage);
}

static void ASSERT_CHECK(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLRETURN rcode)
{
  if(rcode != SQL_SUCCESS && rcode != SQL_SUCCESS_WITH_INFO){
    odbc_print_error(HandleType, Handle);
    assert(0);
  }
}

int main()
{
  HENV henv;
  SQLCHAR OutConnStr[255];
  SQLSMALLINT OutConnStrLen;

  // Apply for an environment handle.
  SQLRETURN rcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
  ASSERT_CHECK(SQL_HANDLE_ENV, henv, rcode);

  // Set the environment attributes of the ODBC version.
  rcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0);
  ASSERT_CHECK(SQL_HANDLE_ENV, henv, rcode);

  // Allocate a connection handle.
  SQLHDBC hdbc; rcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
  ASSERT_CHECK(SQL_HANDLE_DBC, hdbc, rcode);

  // Connect to the data source.
  char* mydriver = (char*)"Driver={OceanBase ODBC 2.0 Driver};Server=xxx.xxx.xxx.xxx;Port=38884;Database=test;User=xxx@oracle;Password=xxx;Option=3;";
  rcode = SQLDriverConnect(hdbc, NULL, (SQLCHAR*)mydriver, strlen((char*)mydriver) + 1, OutConnStr, 255, &OutConnStrLen, SQL_DRIVER_NOPROMPT);
  //rcode = SQLConnect(hdbc, (SQLCHAR *)"oboracle", SQL_NTS, (SQLCHAR *)"test@oracle", SQL_NTS, (SQLCHAR *)"test", SQL_NTS);
  ASSERT_CHECK(SQL_HANDLE_DBC, hdbc, rcode);

  // Create an SQL statement handle.
  SQLHSTMT stmt;
  rcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &stmt);
  ASSERT_CHECK(SQL_HANDLE_STMT, stmt, rcode);

  // Execute the SQL statement.
  rcode = SQLExecDirect(stmt, (SQLCHAR*)"select 1, 'obodbc', 88 from dual", SQL_NTS);
  ASSERT_CHECK(SQL_HANDLE_STMT, stmt, rcode);

  // Bind and obtain data items.
  SQLINTEGER res = SQL_NTS;
  SQLCHAR name[128];
  SQLINTEGER age;
  SQLBindCol(stmt, 2, SQL_C_CHAR, name, sizeof(name), &res);
  SQLBindCol(stmt, 3, SQL_C_SLONG, &age, sizeof(age), &res);
  while ((rcode = SQLFetch(stmt)) != SQL_NO_DATA_FOUND)
  {
    if (rcode == SQL_ERROR) {
      printf("sql error!\n");
    } else {
      printf("name:%s, age:%ld\n", name, age);
    }
  }

  // Release resource handles.
  SQLFreeHandle(SQL_HANDLE_STMT, stmt);
  SQLDisconnect(hdbc);
  SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
  SQLFreeHandle(SQL_HANDLE_ENV, henv);
  return 0;
}

Previous topic

Install and configure the ODBC driver for Linux
Last

Next topic

Basic operations
Next
What is on this page
Install OceanBase Connector/ODBC
Configure a data source
Connection examples
Example 1: Add a data source (for OceanBase Database in Oracle mode)
Example 2: Install OceanBase Connector/ODBC without adding a data source (which will be specified in the code)