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 Database

SQL - V4.3.3

    Download PDF

    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 Database
    3. SQL
    4. V4.3.3
    iconOceanBase Database
    SQL - V 4.3.3
    SQL
    KV
    • V 4.6.0
    • V 4.4.2
    • V 4.3.5
    • V 4.3.3
    • V 4.3.1
    • V 4.3.0
    • V 4.2.5
    • V 4.2.2
    • V 4.2.1
    • V 4.2.0
    • V 4.1.0
    • V 4.0.0
    • V 3.1.4 and earlier

    Build a Java application

    Last Updated:2024-12-02 03:48:29  Updated
    share
    What is on this page
    Prerequisites
    Procedure
    Step 1: Obtain a database connection string
    Step 2: Install the OceanBase Connector/J driver
    Step 3: Write an application
    Step 4: Run the application
    More information

    folded

    share

    This topic describes how to build a Java application with OceanBase Database and OceanBase Connector/J.

    Applicability

    This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.

    Prerequisites

    • A basic database development environment is deployed.

    • The Java environment on your computer is Java JDK 8 or later.

    • You have obtained the installation package of OceanBase Connector/J. If not, obtain it from OceanBase Download Center.

    Procedure

    Step 1: Obtain a database connection string

    Obtain a database connection string from a database deployment engineer or administrator. For example:

    obclient  -h100.88.xx.xx -usys@oracle -p****** -P2881
    

    The database connection string contains parameters required for accessing OceanBase Database. Before you create an application, you can log in to OceanBase Database by using the database connection string, to verify that the parameters are correct.

    The parameters are described as follows:

    • -h: the IP address for connecting to OceanBase Database, which is sometimes the IP address of an OceanBase Database Proxy (ODP).

    • -u: the username for connecting to a tenant, in the format of username@tenant name#cluster name. In Oracle mode, the default username of the administrator is sys. The cluster name is not required when you directly connect to OceanBase Database, but is required when you connect to OceanBase Database through an ODP.

    • -p: the user password.

    • -P: the port for connecting to OceanBase Database, which is also the listening port of the ODP.

    Step 2: Install the OceanBase Connector/J driver

    Decompress the JAR package of OceanBase Connector/J, place it in the local /usr/share/java path, and set the temporary environment variables.

    mv ./oceanbase-client-{version}.jar /usr/share/java
    export CLASSPATH=/usr/share/java/oceanbase-client-{version}.jar:$CLASSPATH
    

    Note

    Perform the preceding operations based on the downloaded file version.

    Step 3: Write an application

    The following sample code of Test.java is for your reference:

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.sql.ResultSet;
    import java.sql.Statement;
    
    public class Test {
        public static void main(String[] args) {
            try {
    
                Class.forName("com.oceanbase.jdbc.Driver");
                Connection connection = DriverManager.getConnection("jdbc:oceanbase://172.30.xx.xx:2881/?pool=false&user=s**@oracle&password=******");
                System.out.println(connection.getAutoCommit());
                Statement sm = connection.createStatement();
                //Create a table named t_meta_form.
                sm.executeUpdate("CREATE TABLE t_meta_form (name varchar(36) , id int)");
                //Insert data.
                sm.executeUpdate("insert into t_meta_form values ('an','1')");
                //Query data and view the output.
                ResultSet rs = sm.executeQuery("select * from t_meta_form");
                while (rs.next()) {
                    String name = rs.getString("name");
                    String id = rs.getString("id");
                    System.out.println(name + ','+ id);
                }
                //Drop the table.
                sm.executeUpdate("drop table t_meta_form");
            }catch (SQLException ex) {
                System.out.println("error!");
                ex.printStackTrace() ;
            }catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
    

    Modify the database connection parameters in the code. Values of the parameters are from the database connection string obtained in Step 1.

    • url: The value of this parameter is obtained from the -h and -P parameters, in the format of jdbc:oceanbase://IP:port/?pool=false. This parameter specifies the IP address and port for connecting to OceanBase Database, which are usually the IP address of an ODP and the port for database access.

    • user: the username for connecting to a tenant, in the format of username@tenant name#cluster name. The value of this parameter is obtained from the -u parameter. In Oracle mode, the default username of the administrator is sys. The cluster name is not required when you directly connect to OceanBase Database, but is required when you connect to OceanBase Database through an ODP.

    • password: the user password. The value of this parameter is obtained from the -p parameter.

    Step 4: Run the application

    After you edit the code, run the following command:

    javac Test.java
    

    After the compilation is completed, execute the sample script. If the following results are returned, you have connected to OceanBase Database, and the sample script is correctly executed.

    java Test
    
    true
    an,1
    

    More information

    For more information about how to use OceanBase Connector/J, see the OceanBase Connector/J documentation.

    Previous topic

    Basic SQL operations (Oracle mode)
    Last

    Next topic

    Build a C application
    Next
    What is on this page
    Prerequisites
    Procedure
    Step 1: Obtain a database connection string
    Step 2: Install the OceanBase Connector/J driver
    Step 3: Write an application
    Step 4: Run the application
    More information