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.0
  • 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
    • 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
    • Create a multi-level collection type
    • 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.0

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Connector/J
  3. V2.2.0

Modify a database

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

DML operations
DDL operations

OceanBase JDBC supports modifying a database through DML and DDL operations.

DML operations

To perform a DML INSERT or UPDATE operation, create a Statement or PreparedStatement object. You can use the PreparedStatement object to run a statement with a set of input parameters. The prepareStatement method of the JDBC Connection object can define a statement, bind variables to parameters, and return the JDBC PreparedStatement object with a statement definition.

The PreparedStatement object uses the setXXX method to bind data to a statement that is ready to be sent to the database.

Example: Use the PreparedStatement object to perform the INSERT operation to add two rows of data to the customers table.

PreparedStatement ps = null;
try{
    ps = conn.prepareStatement ("insert into customers (customerID, name) values (?, ?)");

    ps.setInt (1, 150);              // The first quotation mark (?) corresponds to the customerID.
    ps.setString (2, "Adam");   // The second quotation mark (?) corresponds to the name.

    ps.execute ();

    ps.setInt (1, 207);           
    ps.setString (2, "Alice");   
    ps.execute ();
}

finally{
     if(ps!=null)
     ps.close();
}

DDL operations

To perform a DDL operation, create a Statement or PreparedStatement object.

Example: Using the Statement object to create a table in the database

// Create the customers table and the customerID and name columns.
String query;
Statement st=null;

try{
    query="create table customers " +
          "(customerID int, " +
          "name varchar(50))";
    st = conn.createStatement();
    st.executeUpdate(query);
    }
finally{
     // Close the Statement object.
     st.close();
    }

If the DDL operation needs to be performed again, a new DDL statement must be prepared.

Example: Preparing a DDL statement before the DDL operation is performed again

//
PreparedStatement ps = null;
PreparedStatement ts = null;
try{
    ps = conn.prepareStatement ("insert into customers(customerID, name) values (?, ?)");
 
    // Add new customer Adam numbered 150.
    ps.setInt (1, 150);          // The first quotation mark (?) corresponds to the customerID.
    ps.setString (2, "Adam");   // The second quotation mark (?) corresponds to the name.
    // Insert data.
    ps.execute ();
    
    ts = conn.prepareStatement("truncate table customers"); 
    ts.executeUpdate();
 
 
    // Add new customer Alice numbered 207.
    ps.setInt (1, 207);           // The first quotation mark (?) corresponds to the customerID.
    ps.setString (2, "Alice");   // The second quotation mark (?) corresponds to the name.
    // Insert data.
    ps.execute ();
 
    ts.close();
    ts = conn.prepareStatement("truncate table customers"); 
    ts.executeUpdate();
    }
finally{
     if(ps!=null)
    // Close the Statement object.
     ps.close();
}

Previous topic

Close ResultSet and Statement objects
Last

Next topic

Commit changes
Next
on this page
DML operations
DDL operations