OceanBase logo

OceanBase

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

Product Overview
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

OceanBase

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

Product Overview
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.16

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

Overview of OceanBase Connector/J Compatibility requirements Install and load OceanBase Connector/J 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 source overview Database 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 remarks 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.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 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 & CertificationTicket
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.16
iconOceanBase Connector/J
V 2.4.16
Databases
  • OceanBase Database
  • OceanBase Cloud
  • OceanBase Tugraph
  • Interactive Tutorials
  • OceanBase Best Practices
Tools
  • OceanBase Cloud Platform
  • OceanBase Migration Service
  • OceanBase Developer Center
  • OceanBase Migration Assessment
  • OceanBase Admin Tool
  • OceanBase Loader and Dumper
  • OceanBase Deployer
  • Kubernetes operator for OceanBase
  • OceanBase Diagnostic Tool
  • OceanBase Binlog Service
Connectors and Middleware
  • OceanBase Database Proxy
  • Embedded SQL in C for OceanBase
  • OceanBase Call Interface
  • OceanBase Connector/C
  • OceanBase Connector/J
  • OceanBase Connector/ODBC
  • OceanBase Connector/NET
  • V 2.4.18
  • 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-05-08 09:11:48  Updated
Share
What is on this page
LONG RAW data conversion
LONG data conversion
Example

folded

Share

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

In streaming mode, OceanBase Connector/J generally does not read the data of LONG or LONG RAW columns from the network. Before you call the getXXX method to read column data in your code, the column data remains in the network communication channel. Any connection that does not read the column data will discard the column data from the channel. Although streaming mode effectively utilizes memory and minimizes round-trip communication, it can interfere with other database operations.

To access the data in a LONG column, you can treat the column as a Java InputStream object and use the read method of the InputStream object. You can also retrieve the data as a String or byte array by performing a streaming transfer.

All three streaming types can retrieve LONG and LONG RAW data. The driver performs data conversion based on the character sets of the database and the driver.

Notice

Do not create tables with `LONG` columns. Instead, use large object (LOB) columns: CLOB, NCLOB, and BLOB. LOB columns have significantly fewer usage restrictions compared to LONG columns, so it is recommended to convert existing LONG columns to LOB columns.

LONG RAW data conversion

Calling getBinaryStream returns RAW data. Calling getAsciiStream converts RAW data to hexadecimal and returns the corresponding ASCII. Calling getUnicodeStream converts RAW data to hexadecimal and returns Unicode characters.

LONG data conversion

When you call getAsciiStream to retrieve LONG data, the driver assumes that the underlying data in the database uses the US7ASCII or WE8ISO8859P1 character set. If this assumption is true, the driver returns bytes corresponding to ASCII characters. If the database does not use the US7ASCII or WE8ISO8859P1 character set, calling getAsciiStream will return meaningless information.

When you call getUnicodeStream to retrieve LONG data, you get a Unicode character stream encoded in UTF-16.

When you call getBinaryStream to retrieve LONG data, if the database character set is not US7ASCII or WE8ISO8859P1, the call to getBinaryStream will return UTF-8. If the server-side character set is US7ASCII or WE8ISO8859P1, the call will return a US7ASCII byte stream.

Notice

When receiving LONG or LONG RAW columns as streams, pay special attention to the order of the columns retrieved from the database.

The following table shows the details of LONG and LONG RAW data conversion.

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

Example

One of the functions of the getXXXStream method is to retrieve data incrementally, while getBytes retrieves all data in a single call. Here is an example of retrieving a binary data stream.

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

  1. Create a table named stream01 to store a LONG RAW data column related to the SAMPLE column.

    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 a file named sample.gif.

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

    // Retrieve the first row
    if (rs.next())
    {
        // Retrieve the GIF data in stream form
        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 the preceding example, the InputStream object returned by the getBinaryStream method directly reads data from the database connection.

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

In this example, the getBytes method is used to retrieve the contents of the giftype column. The driver retrieves all data in a single call and stores it in a byte array.

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

// Retrieve the first row
if (rs2.next())
{
   // Retrieve the GIF data in stream form
   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();
   }
}

Because a LONG RAW column can contain up to 2 GB of data, the getBytes example can use more memory than the getBinaryStream example. If you are unsure of the maximum size of data in a LONG or LONG RAW column, use a stream.

Note

  • OceanBase Connector/J automatically streams any LONG and LONG RAW columns. However, in some cases, you may want to avoid streaming data. For example, when the LONG column is small, you may want to retrieve all data in a single call instead of incrementally.
  • To avoid streaming, use the defineColumnType method to redefine the type of the LONG column. For example, you can redefine a LONG or LONG RAW column as a VARCHAR or VARBINARY column. In this case, the driver does not automatically stream data.
  • If you use the defineColumnType method to redefine the column type, you must declare the column type in the query. Otherwise, the executeQuery method fails. In addition, you must convert the Statement object to a oceanbase.jdbc.oceanbaseStatement object.

Previous topic

Overview of Java data streams
Last

Next topic

Overview of LOB data types
Next
What is on this page
LONG RAW data conversion
LONG data conversion
Example