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/J

V2.4.3

  • What is OceanBase Connector J?
    • Overview of OceanBase Connector/J
    • Compatibility requirements
  • Install Driver
    • Install and load the OceanBase Connector/J driver
  • Instructions
    • Quick start
      • Import packages
      • Create a database connection
      • Create a Statement object
      • Run queries and retrieve ResultSet objects
      • Process ResultSet objects
      • Close ResultSet and Statement objects
      • Manage tables and data
      • Commit changes
      • Close a database connection
      • Example
    • Data sources and URL
      • Data source overview
      • Database URL
    • Java data streams
      • Overview of Java data streams
      • LONG and LONG RAW data types
      • Use LOBs
        • Overview of LOB data types
        • LOB data interface
        • LOB locator API
      • CHAR, VARCHAR, and RAW data types
    • Statement caching
      • Overview of statement caching
      • Use statement caching
      • Reuse statement objects
    • Call a stored procedure
    • Handle SQL exceptions
    • Result set
      • Overview of result sets
      • Limitations
      • FetchSize
      • refreshRow
      • useCursorFetch
    • Batch processing
    • Failover and Load-Balancing
      • Failover and load balancing modes
      • LoadBalance strategies
      • Load balancing strategy configuration methods
    • Security features
    • Rich client
    • Network overheads
    • Show Trace
    • Troubleshooting
  • Reference
    • Features specific to the Oracle mode
      • Binary Protocol (Prepared Statements)
        • COM_STMT_PREPARE_EXECUTE
        • COM_STMT_SEND_PIECE_DATA
      • Call PL stored procedures
      • Scrollability of a result set
      • Use ARRAY and STRUCT classes
      • Distributed transactions
        • Overview
        • XA components
        • Distributed transaction examples
      • Obtain comments
      • Data types supported in Oracle mode
      • Error messages in Oracle mode
    • Supported SQL and PL data types
    • Common APIs
      • Overview
      • java.sql.Connection
      • java.sql.CallableStatement
      • java.sql.DatabaseMetaData
      • java.sql.Driver
      • java.sql.PreparedStatement
      • java.sql.ParameterMetaData
      • java.sql.ResultSet
      • java.sql.ResultSetMetaData
      • java.sql.Statement
      • javax.sql.ConnectionPoolDataSource
      • javax.naming.Context
      • javax.sql.PooledConnection
  • Release
    • V2.4
      • OceanBase Connector/J V2.4.3
      • OceanBase Connector/J V2.4.2
      • OceanBase Connector/J V2.4.1
      • OceanBase Connector/J V2.4.0
    • V2.2
      • OceanBase Connector/J V2.2.11
      • OceanBase Connector/J V2.2.10
      • OceanBase Connector/J V2.2.7
      • OceanBase Connector/J V2.2.6
      • OceanBase Connector/J V2.2.3
      • OceanBase Connector/J V2.2.0

Download PDF

Overview of OceanBase Connector/J Compatibility requirements Install and load the OceanBase Connector/J driver Import packages Create a database connection Create a Statement object Run queries and retrieve ResultSet objects Process ResultSet objects Close ResultSet and Statement objects Manage tables and data Commit changes Close a database connection Example Data source overviewDatabase URL Overview of Java data streams LONG and LONG RAW data types CHAR, VARCHAR, and RAW data types Overview of statement caching Use statement caching Reuse statement objects Call a stored procedure Handle SQL exceptions Overview of result sets Limitations FetchSize refreshRow useCursorFetch Batch processing Failover and load balancing modes LoadBalance strategies Load balancing strategy configuration methods Security features Rich client Network overheads Show Trace Troubleshooting Call PL stored procedures Scrollability of a result set Use ARRAY and STRUCT classes Obtain comments Data types supported in Oracle mode Error messages in Oracle mode Supported SQL and PL data types Overview java.sql.Connection java.sql.CallableStatement java.sql.DatabaseMetaData java.sql.Driver java.sql.PreparedStatement java.sql.ParameterMetaData java.sql.ResultSet java.sql.ResultSetMetaData java.sql.Statement javax.sql.ConnectionPoolDataSource javax.naming.Context javax.sql.PooledConnection OceanBase Connector/J V2.4.3 OceanBase Connector/J V2.4.2 OceanBase Connector/J V2.4.1 OceanBase Connector/J V2.4.0 OceanBase Connector/J V2.2.11 OceanBase Connector/J V2.2.10 OceanBase Connector/J V2.2.7 OceanBase Connector/J V2.2.6 OceanBase Connector/J V2.2.3 OceanBase Connector/J V2.2.0
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/J
  3. V2.4.3
iconOceanBase Connector/J
V 2.4.3
  • V 2.4.17
  • V 2.4.16
  • V 2.4.15
  • V 2.4.14
  • V 2.4.5
  • V 2.4.4
  • V 2.4.3
  • V 2.4.2
  • V 2.4.1
  • V 2.4.0
  • V 2.2.11
  • V 2.2.10
  • V 2.2.7
  • V 2.2.6
  • V 2.2.3
  • V 2.2.0

Load balancing strategy configuration methods

Last Updated:2026-04-09 07:21:44  Updated
share
What is on this page
Configure load balancing strategies in the URL
Configure load balancing strategies by using the configuration file
Prerequisites
Content of the configuration file
Example of minimum configuration

folded

share

You can configure load balancing strategies by using the URL or configuration file.

Configure load balancing strategies in the URL

You can specify load balancing information in the ExtendDescription parameter of the URL that connects to OceanBase Connector/J. Default configuration method:

jdbc:oceanbase:[loadbalance:]//@[ExtendDescription]|<hostDescription>[,<hostDescription>...]]/[database][?<key1>=<value1>[&<key2>=<value2>]]

The following example shows the sample settings of the ExtendDescription parameter:

Notice

Each configuration URL has a unique NET_SERVICE_NAME value.

(NET_SERVICE_NAME=(DESCRIPTION=
  (OBLB=ON)                                                    
  (OBLB_RETRY_ALL_DOWNS=120)
  (OBLB_GROUP_STRATEGY=ROTATION)                               
  (OBLB_BLACKLIST=
      (
        REMOVE_STRATEGY=(
          (NAME=TIMEOUT)
          (TIMEOUT=100)
        )
      )                          
      (
        APPEND_STRATEGY =(
          (NAME=RETRYDURATION)
          (RETRYTIMES=3)
          (DURATION=100)
        )
      )
  )
  (ADDRESS_LIST=  
     (OBLB_STRATEGY=SERVERAFFINITY)                          
     (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=port1)(WEIGHT=1))      
     (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=port2)(WEIGHT=10))
  )    
  (ADDRESS_LIST=
     (OBLB_STRATEGY=RANDOM)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
  )
  (ADDRESS_LIST=
     (OBLB_STRATEGY=ROTATION)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
   )
   (CONNECT_DATA=(SERVICE_NAME=OBDATABASE))
)
)

Example:

String url = "jdbc:oceanbase:loadbalance://@(NET_SERVICE_NAME=(DESCRIPTION=
  (OBLB=ON)                                                    
  (OBLB_RETRY_ALL_DOWNS=120)
  (OBLB_GROUP_STRATEGY=ROTATION)                               
  (OBLB_BLACKLIST=
      (
        REMOVE_STRATEGY=(
          (NAME=TIMEOUT)
          (TIMEOUT=100)
        )
      )                          
      (
        APPEND_STRATEGY =(
          (NAME=RETRYDURATION)
          (RETRYTIMES=3)
          (DURATION=100)
        )
      )
  )
  (ADDRESS_LIST=  
     (OBLB_STRATEGY=SERVERAFFINITY)                          
     (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=port1)(WEIGHT=1))      
     (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=port2)(WEIGHT=10))
  )    
  (ADDRESS_LIST=
     (OBLB_STRATEGY=RANDOM)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
  )
  (ADDRESS_LIST=
     (OBLB_STRATEGY=ROTATION)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
   )
   (CONNECT_DATA=(SERVICE_NAME=OBDATABASE))
))/OBDATABASE?rewriteBatchedStatements=true&allowSendParamTypes=true&prepStmtCacheSize=1000";
Connection = DriverManager.getConnection(url);

You can also configure load balancing strategies by using URL Option. The following table describes the parameters.

Note

We recommend that you use URL Option to configure load balancing strategies for OceanBase Connector/J. You can specify the corresponding settings in the Java Database Connectivity (JDBC) URL.

Parameter Description Remarks
retriesAllDown The maximum number of connection retries when all available database nodes cannot be connected. Default value: 120. This parameter has the same meaning as RETRY_ALL_DOWNS in the extended configuration information. The settings in the extended configuration information overwrite those in the URL.
loadBalanceStrategy Supported strategies are RANDOM, ROTATION, and SERVERAFFINITY. N/A
serverAffinityOrder The pairs of host names and port numbers when the SERVERAFFINITY load balancing strategy is used. The pairs of host names and port numbers are separated with commas (,). The hosts specified in this parameter must be a subset of those specified in the Host parameter of this URL, and their case and type must be the same. For example, you cannot use IP addresses of hosts in this parameter while using the corresponding host names in the Host parameter. N/A
loadBalanceBlacklistTimeout The timeout period, in milliseconds, after which a host is added to the blacklist. The blacklist is enabled only if you set this parameter to a positive integer. In other words, if a host cannot be connected after the specified period, it is added to the blacklist. The default value is 0, which indicates that the blacklist is disabled. N/A

Example:

jdbc:oceanbase:loadbalance//host1:port1:5,host2:port2:10/schema?user=usr&password=pwd&loadBalanceStrategy=serverAffinity

Configure load balancing strategies by using the configuration file

In OceanBase Connector/J, you can use the oceanbase.tns_admin system parameter to specify the directory of the configuration file. If you do not specify the directory, the directory is specified by using the OCEANBASE_TNS_ADMIN environment variable. By default, the name of the configuration file is tnsnames.ob. You can use the OCEANBASE_TNS_ADMIN_NAME environment variable to specify a different configuration file name.

The OCEANBASE_TNS_ADMIN_DEAMON environment variable specifies whether to enable the daemon to monitor changes in the configuration file. The default value is true. If you set it to false, OceanBase Connector/J reads the configuration file each time it connects to the database. You can use the OCEANBASE_TNS_ADMIN_NAME variable to change the name of the tns configuration file. By default, the name of the configuration file is tnsnames.ob.

Prerequisites

  • You have specified the use of the configuration file by setting export OCEANBASE_TNS_ADMIN=/path or oceanbase.tns_admin=/path. oceanbase.tns_admin is a Java Virtual Machine (JVM) parameter.

  • You have specified the name of the configuration file by setting export OCEANBASE_TNS_ADMIN_NAME=/tnsyournames.ob or export oceanbase.tns_admin_name=tnsyournames.ob. oceanbase.tns_admin_name is a JVM parameter. By default, the tnsnames.ob configuration file is used. We do not recommend that you specify the file name.

  • To disable the daemon, you can set the export OCEANBASE_TNS_ADMIN_DEAMON environment variable or the oceanbase.tns_admin_deamon JVM parameter to false.

Content of the configuration file

The content of the configuration file must be in the same format as that of the extended configuration information. However, the configuration file can contain multiple DESCRIPTION parameters and each DESCRIPTION parameter belongs to a NET_SERVICE_NAME.

The following sample code indicates that the configuration file contains three NET_SERVICE_NAME values: TNS_TEST_NORMAL, TNS_TEST_WEIGHT, and TNS_TEST_GROUP.

TNS_TEST_NORMAL=
 (DESCRIPTION=
  (ADDRESS_LIST =
   (OBLB_STRATEGY=RANDOM)
   (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=port1))
   (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=port1))
   (CONNECT_DATA=(SERVICE_NAME=ORCLCDB))
  )
 )
TNS_TEST_WEIGHT=
 (DESCRIPTION=
  (ADDRESS_LIST =
   (OBLB_STRATEGY=SERVERAFFINITY)
   (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=port1)(WEIGHT=4))
   (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=port2)(WEIGHT=10))
   (CONNECT_DATA=(SERVICE_NAME=ORCLCDB))
  )
 )
TNS_TEST_GROUP=(DESCRIPTION=
  (OBLB=ON)                                                    
  (OBLB_RETRY_ALL_DOWNS=120)
  (OBLB_GROUP_STRATEGY=ROTATION)                               
  (OBLB_BLACKLIST=  
      (
        REMOVE_STRATEGY=(
          (NAME=TIMEOUT)
          (TIMEOUT=100)
        )
      )                          
      (
        APPEND_STRATEGY =(
          (NAME=RETRYDURATION)
          (RETRYTIMES=3)
          (DURATION=100)
        )
      )
  )
  (ADDRESS_LIST=   
     (OBLB_STRATEGY=SERVERAFFINITY)                          
     (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=port1)(WEIGHT=1))      
     (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=port2)(WEIGHT=10))
  )    
  (ADDRESS_LIST=
     (OBLB_STRATEGY=RANDOM)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
  )
  (ADDRESS_LIST=
     (OBLB_STRATEGY=ROTATION)
     (ADDRESS=(PROTOCOL=tcp)(HOST=host3)(port=port3))
     (ADDRESS=(PROTOCOL=tcp)(HOST=host4)(port=port4))
   )
   (CONNECT_DATA=(SERVICE_NAME=OBDATABASE))
)

Example of minimum configuration

The following example shows the minimum extended configuration information for the load balancing of OceanBase Connector/J:

String connU = "jdbc:oceanbase:loadbalance://@TNS_TEST_NORMAL/test?rewriteBatchedStatements=true&allowSendParamTypes=true&prepStmtCacheSize=1000&prepStmtCacheSqlLimit=4096&cachePrepStmts=true";
Connection sharedConnection = DriverManager.getConnection(connU, "usr", "password");

The URL in the example contains the following key information:

  • jdbc:oceanbase:loadbalance indicates that the LoadBalance mode is enabled.

  • @TNS_TEST_NORMAL specifies the value of NET_SERVICE_NAME. If the configuration file contains multiple NET_SERVICE_NAME values, each value must start with an at sign (@).

The following example shows the minimum configuration of TNS_TEST_NORMAL for using the default strategy:

TNS_TEST_NORMAL=
 (DESCRIPTION=
  (ADDRESS_LIST =
   (ADDRESS=(PROTOCOL=tcp)(HOST=host1)(PORT=port1))
   (ADDRESS=(PROTOCOL=tcp)(HOST=host2)(PORT=port2))
   (CONNECT_DATA=(SERVICE_NAME=ORCLCDB))
  )
 )

Previous topic

LoadBalance strategies
Last

Next topic

Security features
Next
What is on this page
Configure load balancing strategies in the URL
Configure load balancing strategies by using the configuration file
Prerequisites
Content of the configuration file
Example of minimum configuration