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.7
  • What's New
  • What is OceanBase Connector J?
    • Overview of OceanBase Connector/J
    • Compatibility requirements
  • Instructions
    • Install and load the OceanBase Connector/J driver
    • Connect Python applications to OceanBase Database
    • Basic operations
      • 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
      • Example
    • Handle SQL exceptions
    • Use CallableStatements to call stored procedures
    • 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 interface
      • LOB locator API
      • CHAR, VARCHAR, and RAW data types
    • Data sources and URL
      • Data source overview
      • Data source characteristics and properties
      • Create and connect to a data source instance
      • Database URL
    • Result set
      • Overview of result sets
      • Limits
      • FetchSize
      • refreshRow
      • useCursorFetch
    • Statement caching
      • Overview of statement caching
      • Use statement caching
      • Reuse statement objects
    • Failover and load balancing modes
    • Batch processing
    • Security features
    • SQL NetworkCostInfo
    • Troubleshooting
    • Common APIs
      • Overview of 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
    • Binary Protocol (Prepared Statements)
      • COM_STMT_PREPARE_EXECUTE
      • COM_STMT_SEND_PIECE_DATA
    • Call PL stored procedures
    • Result set performance
    • 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.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

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

Manage tables and data

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

DML operations
DDL operations

OceanBase Connector/J allows you to modify database tables and data by using 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 a Connection object can define a statement, bind variables to parameters, and return a PreparedStatement object with a statement definition.

The PreparedStatement object uses the setXXX method to bind data to a statement 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 ? corresponds to customerID.
    ps.setString (2, "Adam");     // The second ? corresponds to 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: Use a Statement object to create a table in the database.

// Create the customers table and the customerID and name columns.

String query;
Statement st=null;
query="create table customers " +
          "(customerID int, " +
          "name varchar(50))";
st = conn.createStatement();
st.executeUpdate(query);
st.close();    //Close the statement

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

Example: Prepare a DDL statement before a DDL operation is performed again.

PreparedStatement ps = null;
PreparedStatement ts = null;
ps = conn.prepareStatement ("insert into customers(customerID, name) values (?, ?)");   // The first ? corresponds to customerID. The second ? corresponds to name. 
ps.setInt (1, 150);            // Add a new customer whose name is Adam and ID is 150. 
ps.setString (2, "Adam");      
ps.execute ();    
ts = conn.prepareStatement("truncate table customers"); 
ts.executeUpdate();
ps.setInt (1, 207);            // Add a new customer whose name is Alice and ID is 207.
ps.setString (2, "Alice");      
ps.execute (); 
ts.close();
ts = conn.prepareStatement("truncate table customers"); 
ts.executeUpdate();
if(ps!=null)
     ps.close();     // Close the statement

Previous topic

Close ResultSet and Statement objects
Last

Next topic

Commit changes
Next
on this page
DML operations
DDL operations