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.5

  • 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
      • Examples
    • 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 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 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
      • com.oceanbase.jdbc.ObPrepareStatement
  • Release Notes
    • V2.4
      • 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

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 Examples 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 Rich client Logging Network overheads Show Trace Security features 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 com.oceanbase.jdbc.ObPrepareStatement 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 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.5
iconOceanBase Connector/J
V 2.4.5
  • 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

LONG and LONG RAW data types

Last Updated:2026-04-09 07:21:37  Updated
share
What is on this page
Convert LONG RAW data
Convert LONG data
Examples

folded

share

When one or more LONG or LONG RAW columns are selected in a query, OceanBase Connector/J transmits these columns to the client in streaming mode.

In streaming mode, OceanBase Connector/J generally does not read data of a LONG or LONG RAW column from the network. Before OceanBase Connector/J calls the getXXX method to read the column data, the column data is retained on the network communication channel. If an operation other than data reading is performed, the column data will be discarded from the channel. In streaming mode, the memory capacity is fully utilized, and the round-trip communication is minimized, but other database operations are affected.

To access data in a LONG column, you can treat this column as a Java InputStream object, and use the read method of the InputStream object to obtain the data. You can also treat the data as a String or byte array, and obtain the data through stream transmission.

You can obtain LONG and LONG RAW data by using all the three types of data streams. OceanBase Connector/J converts the data based on the character sets of the database and OceanBase Connector/J.

Notice

Do not create tables with a LONG column. Instead, you can use LOB columns such as CLOB, NCLOB, or BLOB columns. Use limitations on LOB columns are far less than those on LONG columns. Therefore, we recommend that you convert the existing LONG columns into LOB columns.

Convert LONG RAW data

The getBinaryStream method returns RAW data. The getAsciiStream method converts RAW data into hexadecimal data and returns the corresponding ASCII values. The getUnicodeStream method converts RAW data into hexadecimal data and returns Unicode characters.

Convert LONG data

When you call the getAsciiStream method to obtain LONG data, OceanBase Connector/J assumes that the US7ASCII or WE8ISO8859P1 character set is used for the underlying data in the database. If the assumption is true, OceanBase Connector/J returns the bytes corresponding to the ASCII characters. If the database is not using the US7ASCII or WE8ISO8859P1 character set, the getAsciiStream method returns meaningless information.

When the getUnicodeStream method is used to obtain LONG data, the method returns a UTF-16-encoded Unicode character stream.

When the getBinaryStream method is used to obtain LONG data, if the database is not using the US7ASCII or WE8ISO8859P1 character set, the getBinaryStream method returns UTF-8-encoded data. If the server uses the US7ASCII or WE8ISO8859P1 character set, the method returns US7ASCII byte streams.

Notice

When a LONG or LONG RAW column is received as a stream, observe the order of the columns retrieved from the database.

The following table describes the conversion of different types of LONG and LONG RAW data streams.

Data type BinaryStream AsciiStream UnicodeStream
LONG Bytes represent Unicode UTF-8-encoded characters. If the database uses the US7ASCII or WE8ISO8859P1 character set, these bytes represent characters in the US7ASCII or WE8ISO8859P1 character set. Bytes represent ISO-Latin-1 (WE8ISO8859P1)-encoded characters. Bytes represent Unicode UTF-16-encoded characters.
LONG RAW Data remains unchanged. Data is converted into ASCII hexadecimal bytes. Data is converted into Unicode hexadecimal bytes.

Examples

The getXXXStream method is able to return data in an incremental manner, while the getBytes method returns all data in one call. The following examples show how to obtain a binary data stream.

Example 1: Use the getBinaryStream method to obtain LONG RAW data

  1. Create table stream01 that stores the LONG RAW column related to the name SAMPLE.

    CREATE TABLE stream01 (name VARCHAR2 (50), giftype LONG RAW);
    INSERT INTO stream01 VALUES ('SAMPLE', '1234567890123');
    
  2. Write the data in the LONG RAW column to the sample.gif file.

    ResultSet rs = st.executeQuery 
    ("select giftype from stream01 where NAME='SAMPLE'");
    
  3. Use the getBinaryStream method to obtain LONG RAW data.

    // Obtain the first row.
    if (rs.next())
    {
        // Obtain GIF data as a stream.
        InputStream gif_type = rs.getBinaryStream (1);
       try
       {
          FileOutputStream file = null;
          file = new FileOutputStream ("sample.gif");
          int chunk;
          while ((chunk = gif_type.read()) != -1)
             file.write(chunk);
       }
       catch (Exception e)
       {
          String err = e.toString();
          System.out.println(err);
       }
       finally
       {
          if file != null()
             file.close();
       }
    } 
    

In this example, the InputStream object returned by the getBinaryStream method directly reads data from the database connection.

Example 2: Use the getBytes method to obtain LONG RAW data

In this example, the getBytes method is used to obtain content of the giftype column. OceanBase Connector/J obtains all data in one call and stores the data in a byte array.

ResultSet rs2 = st.executeQuery 
                  ("select giftype from streame01 where NAME='SAMPLE'"); 

// Obtain the first row.
if (rs2.next())
{
   // Obtain GIF data as a stream.
   byte[] bytes = rs2.getBytes(1);
   try
   {
      FileOutputStream file = null;
      file = new FileOutputStream ("sample2.gif");
      file.write(bytes);
   }
   catch (Exception e)
   {
      String err = e.toString();
      System.out.println(err);
   }
   finally
   {
      if file != null()
         file.close();
   }
}

A LONG RAW column can contain up to 2 GB of data. Therefore, compared with the getBinaryStream method, the getBytes method uses more memory capacity. If the maximum size of data in the LONG or LONG RAW column is unknown, use a stream.

Note

  • OceanBase Connector/J can automatically transmit any LONG or LONG RAW column by using streams. However, in some cases, you may want to avoid stream transmission. For example, when the LONG column contains a small amount of data, you may expect the data to be returned in one call but not incrementally.
  • To avoid stream transmission, use the defineColumnType method to redefine the type of the LONG column. For example, you can redefine the LONG or LONG RAW column into the VARCHAR or VARBINARY type, so OceanBase Connector/J does not automatically transmit data by using streams.
  • If you use the defineColumnType method to redefine the column type, you must declare the column type in the query. Otherwise, executeQuery will fail. In addition, you must convert the Statement object into oceanbase.jdbc.oceanbaseStatement.

Previous topic

Overview of Java data streams
Last

Next topic

Overview of LOB data types
Next
What is on this page
Convert LONG RAW data
Convert LONG data
Examples