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.2.3
  • What is OceanBase Connector J?
    • JDBC overview
    • Compatibility requirements
  • Instructions
    • Install OceanBase Client
    • Basic operations
      • Import packages
      • Create a database connection
      • Create a Statement object
      • Run queries and retrieve ResultSet objects
      • Process a ResultSet object
      • Close ResultSet and Statement objects
      • Modify a database
      • Commit changes
      • Close a database connection
    • Handle SQL exceptions
    • Java data streams
      • Overview of Java data streams
      • LONG and LONG RAW data types
      • LOB data types
    • Use LOBs
      • Overview of LOB data types
      • LOB data API
      • LOB locator API
      • CHAR, VARCHAR, and RAW data types
    • Use CallableStatements to call stored procedures
    • Data sources and URL
      • Data source overview
      • Data source characteristics and properties
      • Create and connect to a data source instance
      • Database URL
    • Result set
      • Limits and degradation rules
      • Fetch size
      • Refetch rows
      • Cursor result sets
    • Statement caching
      • Statement caching overview
      • Use statement cache
      • Reuse statement objects
    • Failover and load balancing modes
    • Batch processing
    • JDBC security features
    • SQL NetworkCostInfo
    • Troubleshooting
    • Common APIs
      • 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
    • Reference
      • Supported SQL and PL data types
  • Features specific to the Oracle mode
    • Call PL stored procedures
    • Result set performance
    • Use ARRAY and STRUCT classes
    • Distributed transactions
      • Overview of distributed transactions
      • XA components
      • Distributed transaction examples
    • Error messages in Oracle mode
    • Data types supported in Oracle mode
  • Release Notes
    • V2.2
      • OceanBase Connector/J V2.2.11
      • OceanBase Connector/J V2.2.10
      • 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.2.3

SQL NetworkCostInfo

Last Updated:2026-09-04 08:24:25

Related APIs
Examples

SQL NetworkCostInfo allows you to obtain network overhead data by using some fine-grained APIs.

Related APIs

All the APIs listed in the following table are at the Connection level and require forced type conversion when they are executed to obtain detailed time values.

API
Description
Parameter
Unit of return value
networkStatistics Specifies whether to enable statistics collection. true: enables statistics collection. false: disables statistics collection. Default value: false Empty
getLastPacketCostTime Obtains the round-trip time of the last packet. Empty ms
getLastPacketReponseTimestamp Obtains the packet return timestamp of the last packet. Empty ms
getLastPacketSendTimestamp Obtains the sending timestamp of the last packet. Empty ms
clearNetworkCostInfo Clears previously cached data. Empty Empty

Examples

 public void testCostTime() {
        try {
            Connection conn = sharedConnection;
            ((OceanBaseConnection) conn).networkStatistics(true);
            PreparedStatement ps = conn
                .prepareStatement("insert into " + tableName2 + " values(?)");
            long ms = ((OceanBaseConnection) conn).getLastPacketCostTime();
            System.out.println("prepareStatement  cost info  = " + ms + "ms");
            /*  getNetWorkCostInfo gets the information of the last network transmission, setInt will not perform network transmission, so it needs to be cleaned up*/
            ((OceanBaseConnection) conn).clearNetworkCostInfo();
            ms = ((OceanBaseConnection) conn).getLastPacketCostTime();
            ps.setInt(1, 1);

            System.out.println("setInt   cost info  = " + ms + "ms");
            ps.execute();
            ms = ((OceanBaseConnection) conn).getLastPacketCostTime();
            long sendTs = ((OceanBaseConnection) conn).getLastPacketSendTimestamp();
            long responseTs = ((OceanBaseConnection) conn).getLastPacketResponseTimestamp();
            System.out
                .println(" (responseTs - sendTs) + \"m's\" = " + (responseTs - sendTs) + "ms");
            System.out.println("execute  cost info  = " + ms + "ms");
            ((OceanBaseConnection) conn).networkStatistics(false);
            ms = ((OceanBaseConnection) conn).getLastPacketCostTime();
        } catch (SQLException e) {
            Assert.assertEquals("Cant get network cost info while setNetworkStatisticsFlag(true)",
                e.getMessage());
        }

    }

Previous topic

JDBC security features
Last

Next topic

Troubleshooting
Next
on this page
Related APIs
Examples