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 - V3.2.4Enterprise Edition

    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. V3.2.4
    iconOceanBase Database
    SQL - V 3.2.4Enterprise Edition
    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
    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

    SpringBatch connection example

    Last Updated:2023-10-24 09:23:03  Updated
    Share
    What is on this page
    Environment configuration
    Configure dependencies
    Configuration file
    Sample code

    folded

    Share

    This topic provides a SpringBatch connection example.

    Environment configuration

    • JDK 1.8

    • OceanBase Database V3.x (MySQL/Oracle mode)

    • SpringBatch integrated based on SpringBoot

    Configure dependencies

      <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-batch</artifactId>
      </dependency>
      <!--Database driver-->
      <dependency>
       <groupId>com.alipay.oceanbase</groupId>
       <artifactId>oceanbase-client</artifactId>
       <version>2.4.0</version>
      </dependency>
      <!--Connection pool-->
      <dependency>
       <groupId>com.alibaba</groupId>
       <artifactId>druid</artifactId>
       <version>1.1.22</version>
      </dependency>
      <!--Automatic table creation based on entity classes-->
      <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-data-jpa</artifactId>
      </dependency>
    
      <!--Other SpringBoot core dependencies are omitted here.    -->
    

    Configuration file

    # yml file:
    spring:
      datasource:
        url: jdbc:oceanbase://10.100.xxx.xxx:18815/test
        driver-class-name: com.alipay.oceanbase.jdbc.Driver
    #    username: admin@mysql
        username: admin@oracle
        password: ******
      jpa:
        hibernate:
          ddl-auto: update
    

    Sample code

    Call the database write class method to write data as follows:

    1. Create the required classes.

      Entity classes: People and PeopleDESC

      //Basic people class
      
      @Entity
      @Table(name = "PEOPLE")
      public class People {
          @Id
          @GeneratedValue
          private int id;
          private String lastName;
          private String firstName;
          //...      Omitted
      }
      
      //The peopledesc class after data processing, with the desc attribute added
      
      @Entity
      @Table(name = "OK_PEOPLE")
      public class PeopleDESC {
      
          @Id
          @GeneratedValue  //strategy = AUTO / IDENTITY / SEQUENCE  None of the three primary key generation strategies are supported.
          private int id;
          private String lastName;
          private String firstName;
          private String desc1;
          //...      Omitted
      }
      

      Batch processing classes: AddPeopleDescProcessor and AddDescPeopleWriter

      //The processor that adds the desc attribute to the people class and returns the peopledesc class.
      
      public class AddPeopleDescProcessor implements ItemProcessor<People, PeopleDESC> {
      
          public PeopleDESC process(People item) throws Exception {
      
              return new PeopleDESC(item.getId() ,
                                    item.getLastName(),
                                    item.getFirstName(),
                                    Thread.currentThread().getName());
          }
      }
      
    2. Write peopledesc to the classes of the database.

      //Write peopledesc to the classes of the database.
      
      public class AddDescPeopleWriter implements ItemWriter<PeopleDESC> {
          private JdbcTemplate jdbcTemplate;
          public void setDataSource(DataSource dataSource) {
              this.jdbcTemplate = new JdbcTemplate(dataSource);
          }
      
          public JdbcTemplate getJdbcTemplate() {
              return jdbcTemplate;
          }
      
          public void write(List<? extends PeopleDESC> items) throws Exception {
              for (PeopleDESC peopleDESC : items) {
                  this.jdbcTemplate
                          .update("insert into ok_people (id,first_name,last_name,desc1) values (?, ?, ?, ?)",
                                  peopleDESC.getId(), peopleDESC.getFirstName(),
                                  peopleDESC.getLastName(), peopleDESC.getDesc());
              }
          }
      }
      
    3. When you start the spring-data-jpa project, tables are automatically created based on the entity classes People and PeopleDESC. The sample result is as follows.

      SpringBatch connection example - 1

    4. Add test data to people in batches.

      public void addData(){
              jdbcTemplate = new JdbcTemplate(dataSource);
              StringBuilder stringBuilder = new StringBuilder("");
              for (int i = 1 ; i<=100 ; i++){
                  stringBuilder.append("insert into people values ("+i+",'first_test"+i+"','last_test"+i+"');");
                  jdbcTemplate.execute(stringBuilder.toString());
                  stringBuilder.delete(0, stringBuilder.length());
              }
          }
      

      The test result is as follows:

      SpringBatch connection example - 2

    5. Execute the batch processing method.

       public void writerTest() throws Exception {
              //Obtain the result set of the people table.
              String sql = "select * from people;";
              preparedStatement = dataSource.getConnection().prepareStatement(sql);
              ResultSet resultSet = preparedStatement.executeQuery();
              List list = new ArrayList<PeopleDESC>();
              //Process the result set by using the processor that adds the desc attribute, and encapsulate the data into a List<PeopleDESC>.
              while (resultSet.next()){
                  People people = peopleRowMapper.mapRow(resultSet, resultSet.getRow());
                  PeopleDESC desc = addPeopleDescProcessor.process(people);
                  list.add(desc);
              }
              //Call the database write class method to write data.
              addDescPeopleWriter.setDataSource(dataSource);
              addDescPeopleWriter.write(list);
          }
      

    Previous topic

    SpringBoot connection example
    Last

    Next topic

    SpringJDBC connection example
    Next
    What is on this page
    Environment configuration
    Configure dependencies
    Configuration file
    Sample code