OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Connector/J

V2.4.17
  • What is OceanBase Connector J?
    • Overview of OceanBase Connector/J
    • Compatibility requirements
  • Install Driver
    • Install and load OceanBase Connector/J
  • Instructions
    • Quick start
      • Import packages
      • Establish 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
      • Examples
    • Data sources and URL
      • Data source overview
      • Database URL
      • clientInfoProvider
    • 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 interface
      • 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
    • Rich client
    • Logging
    • Network overheads
    • Show Trace
    • Security features
    • 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 remarks
      • 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
      • com.oceanbase.jdbc.ObPrepareStatement
  • Release Notes
    • V2.4
      • OceanBase Connector/J V2.4.17
      • OceanBase Connector/J V2.4.16
      • OceanBase Connector/J V2.4.15
      • OceanBase Connector/J V2.4.14
      • OceanBase Connector/J V2.4.13
      • OceanBase Connector/J V2.4.12
      • OceanBase Connector/J V2.4.11
      • OceanBase Connector/J V2.4.8
      • OceanBase Connector/J V2.4.5
      • OceanBase Connector/J V2.4.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

Document Feedback
  1. Documentation Center
  2. OceanBase Connector/J
  3. V2.4.17

Rich client

Last Updated:2026-09-28 06:59:15

Workflow
Enable the rich client feature
Examples

The rich client feature integrates the overall routing and forwarding capabilities of OceanBase Database Proxy (ODP) into OceanBase Connector/J. In this way, ODP nodes do not need to be separately deployed or managed for application systems. The rich client feature is applicable to scenarios in which the application server and the database server are interconnected over network, the application server has sufficient resources, and the customer does not use or want to use a load balancer, or the customer demands a lower access latency.

Workflow

The following figure shows how to use a rich client to access OceanBase Database. Rich client.png

Rich client components of OceanBase Connector/J are as follows:

  • JDBC-ObProxySocket: the JDBC driver for the rich client feature. It implements multiple Java Native Interfaces (JNIs) and starts the backend worker threads of ODP for interactions with the backend database.
  • OBProxy_so: the dynamic library of overall capabilities of ODP. It provides interfaces for starting worker threads at the backend and processes and forwards all database requests.

You can use your ODP account to log in to a rich client and adjust related ODP parameters. However, to use this login method, you must specify a domain name socket on the local server. The dynamic library of the rich client has all log capabilities of ODP. By default, a hidden directory named .obproxy is created in the current directory on the application server. This hidden directory contains a log directory where the files of ODP running logs are stored. The dynamic library logs generated by the rich client can be automatically cleared. The log_dir_size_threshold parameter specifies the maximum disk usage that triggers the automatic clearing of these logs. After the application system is restarted, the log clearing will resume.

Enable the rich client feature

Note

At present, the rich client feature can be used only on Linux systems and is not supported on Windows systems.

  1. Download the JAR installation package of OceanBase Connector/J and RPM installation package of ODP of the corresponding versions.

  2. Install ODP. The installation command for Linux systems is as follows:

    rpm -ivh obproxy-x.x.x-x.x.x.rpm;
    

    Note

    At present, the rich client feature is supported in ODP V3.3.0, V3.3.1, V4.0.0, and later.

  3. Create a soft link to the dynamic library in the /u01/obproxy/lib/libobproxy_so.so directory. If this directory does not exist, search for the directory of libobproxy_so.so by using -Djava.library.path.

  4. Enable the rich client feature by using the URL connection setting attribute obProxySocket of OceanBase Connector/J. You can specify the log output level for ODP when you start the rich client or during the running of the client. Here is an example:

    # Start the rich client based on the RootService list:
    &obProxySocket={\"proxy_config\":\"rootservice_cluster_name=***,rootservice_list=10.XXX.XXX.XXX:2727,proxy_mem_limited=1G,work_thread_num=8,syslog_level=INFO,enable_client_ip_checkout=false,check_tenant_locality_change=false,enable_async_pull_location_cache=false,enable_compression_protocol=true,enable_async_log=true,syslog_level=INFO\"}
    
    # Start the rich client based on OCP_CONFIG_URL:
    &obProxySocket={\"proxy_config\":\"rootservice_cluster_name=***,obproxy_config_server_url=***,proxy_mem_limited=1G,work_thread_num=8,syslog_level=INFO,enable_client_ip_checkout=false,check_tenant_locality_change=false,enable_async_pull_location_cache=false,enable_compression_protocol=true,enable_async_log=true,syslog_level=INFO\"}
    

    The value of obProxySocket is in the JSON format. At present, only one key-value pair is supported, in which key is proxy_config, and value is an ODP parameter. For more information, see ODP parameters.

    To use the rich client feature, you must set the cluster information in either of the following ways:

    • Method 1: Set obproxy_config_server_url, which specifies the access URL of OceanBase Cloud Platform (OCP).
    • Method 2: Set the RootService list by using the rootservice_list and rootservice_cluster_name parameters.

    The following table describes the recommended parameter configurations for the rich client feature.

    Parameter
    Default value
    Recommended value
    Description
    automatic_match_work_thread true false If this parameter is set to true, the number of threads for the rich client is min(work_thread_num, number of CPU cores), where work_thread_num is a parameter.
    work_thread_num 128 8 The number of threads, which is affected by automatic_match_work_thread.
    proxy_mem_limited 2G 16G The maximum memory for the rich client. When the memory used by the rich client exceeds the value of proxy_mem_limited, the threads of the rich client automatically exit.
    enable_strict_kernel_release true false Specifies whether to check the kernel version. The rich client cannot be started if the check fails.
    log_dir_size_threshold 64G 1G The maximum disk space for log files. When this value is exceeded, logs are automatically cleared.
    syslog_level INFO INFO/ERROR The log output level. We recommend that you set the log output level to INFO in a production system. If logs do not need to be output, you can set the log level to ERROR.
  5. After the rich client feature is enabled, you can use OceanBase Connector/J to interact with the database.

Examples

The following example illustrates how to use a rich client in an environment in which OceanBase Connector/J V2.3.0 and ODP V3.3.0 are installed.

  1. Create a test case named TestOBClientVC.java.

    import java.io.*;
    import java.sql.*;
    import static java.lang.Thread.sleep;
    
    public class TestOBClientVC {
        public static int useVC = 0;
        public static final String obproxyConfig = "&obProxySocket={\"app_name\":\"mytest\",\"proxy_config\":\"rootservice_cluster_name=***,rootservice_list=10.XXX.XXX.XXX:2727,proxy_mem_limited=2G,work_thread_num=8,syslog_level=DEBUG\"}";
    
        public static Connection getObConnection() throws Exception {
           // Set the connection information.
            final String DRIVER_NAME = "com.alipay.oceanbase.jdbc.Driver";
            final String URL = "jdbc:oceanbase://10.XXX.XXX.XXX:20211/test?useSSL=false&useServerPrepStmts=true&log=true";
            final String USER_NAME = "root@***";
            final String PASSWORD = "";
    
            // Load the driver class of MySQL.
            Class.forName(DRIVER_NAME);
            // Obtain a database connection.
            if (useVC != 0) {
                return (Connection) DriverManager.getConnection(URL + obproxyConfig, USER_NAME, PASSWORD); // clientVC
            } else {
                return (Connection) DriverManager.getConnection(URL, USER_NAME, PASSWORD); // tcp socket
            }
        }
    
         public static void test_text_protocol() {
            Connection conn = null;
            try {
                conn = getObConnection();
                System.out.println("get connection succ");
                ResultSet rs = conn.createStatement().executeQuery("select 'hello obproxy!' from dual");
    
                if (rs.next()) {
                  System.out.println("text:" + rs.getString(1));
                }
             } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public static void test_binary_protocol() {
           Connection conn = null;
           try {
               conn = getObConnection();
               PreparedStatement pstmt = conn.prepareStatement("select ? from dual");
               pstmt.setString(1, "hello obproxy!");
               pstmt.execute();
               ResultSet rs = pstmt.getResultSet();
    
               if (rs.next()) {
                 System.out.println("text:" + rs.getString(1));
               }
           } catch (Exception e) {
               e.printStackTrace();
           }
        }
    
    
        public static void main(String args[])  {
          try {
            // test_text_protocol();
            useVC = 1;
            test_text_protocol();
            test_binary_protocol();
            System.out.println("jdbc test pass");
            // sleep(600000);
          } catch (Exception e) {
            e.printStackTrace();
          }
        }
    }
    
  2. Compile TestOBClientVC.

    javac -cp ./oceanbase-client-2.4.1.jar TestOBClientVC.java
    
  3. Execute TestOBClientVC.

    java -cp $CLASSPATH:oceanbase-client-2.4.1.jar TestOBClientVC
    

Previous topic

Load balancing strategy configuration methods
Last

Next topic

Logging
Next
on this page
Workflow
Enable the rich client feature
Examples