This topic describes how to connect to and access OceanBase Database in Oracle-compatible mode. Currently, you can connect to OceanBase Database by using a client, driver, ORM framework, or connection pool.
Choose a client to connect to OceanBase Database
When connecting to an Oracle-compatible tenant of OceanBase Database, you can use the following command-line client tools:
OceanBase Client (OBClient)
OBClient is an interactive query tool that supports batch processing and must be installed separately. It provides a command-line user interface and acts as the client when it connects to the database, and it supports both Oracle-compatible and MySQL-compatible tenants in OceanBase Database.
To run OBClient, you must specify the connection information of the OceanBase tenant. After you connect to OceanBase Database, you can use OBClient to run database commands (including common MySQL commands), SQL statements, and PL statements to perform the following tasks:
Calculate, store, and print query results.
Create database objects, check and modify object definitions.
Develop and run batch processing scripts.
Perform database management and modify parameters.
For more information about how to connect to an OceanBase tenant by using OceanBase Client, see Connect to an OceanBase tenant by using OBClient.
OceanBase Developer Center (ODC)
OceanBase Developer Center (ODC) is an enterprise-level database development platform tailored for OceanBase Database.
ODC supports connecting to both MySQL-compatible and Oracle-compatible tenants in OceanBase Database. It provides database developers with features such as daily development operations, WebSQL, SQL diagnostics, session management, and data import and export.
For more information about how to connect to an OceanBase tenant by using OceanBase Developer Center, see Connect to OceanBase Database by using ODC.
GUI-based database management tools
In addition to command-line tools, you can use the following GUI tools to connect to and manage OceanBase Database:
DBeaver
DBeaver is a general-purpose database client that supports connecting to Oracle-compatible tenants of OceanBase Database through the Oracle driver. It provides an intuitive GUI and supports features such as SQL editing, data browsing, and table design.
Navicat
Navicat is a powerful database management tool that supports connecting to Oracle-compatible tenants of OceanBase Database through the Oracle driver. It provides features such as data visualization, data synchronization, and report generation.
Choose a driver or ORM framework to connect to OceanBase Database
C
C drivers
OBCI
OBCI (OceanBase Call Interface) is a C language interface for OceanBase that is compatible with Oracle OCI. It provides fully compatible features and functionality with Oracle OCI.
OBCI enables you to use the C language to manipulate data in OceanBase Database. It offers standard database access functionality as a dynamic link library (the OBCI library). Applications can link to this library at runtime to use these features.
The OBCI provided by OceanBase is an OceanBase C language call interface compatible with Oracle OCI, offering OCI-compatible features and functionality. When using C language applications written with Oracle OCI, you do not need to modify the application source code. You only need to specify the runtime library as the OBCI library during linking. This library file is installed by default in the
/u01/obclient/libpath.For an example of connecting to OceanBase Database from a C application, see Create a C sample application.
ODBC
ODBC (Open Database Connectivity) is a standard database access interface that allows you to connect to and operate on different types of databases in a unified way. The ODBC driver provided by OceanBase allows applications to interact with OceanBase Database using standard SQL syntax, without worrying about the underlying implementation details. With ODBC, you can develop applications in various programming languages (such as C and C++) and achieve cross-database compatibility and flexibility. With the ODBC driver, developers can easily connect to OceanBase in various environments, which simplifies data access and improves development efficiency.
For an example of connecting to OceanBase Database from a C application by using ODBC, see Connect to OceanBase Database from a C application.
C ORM frameworks
SqlSugar
SqlSugar is a concise and easy-to-use C# ORM (Object-Relational Mapping) framework designed to help developers perform database operations quickly and efficiently. SqlSugar provides powerful data query and manipulation capabilities and supports multiple mainstream databases, including OceanBase. With SqlSugar, developers can execute complex database operations using simple C# code, avoiding tedious SQL statement writing and improving development efficiency.
For an example of connecting to OceanBase Database by using SqlSugar, see Connect to OceanBase Database from a C application.
Java
Java drivers
OceanBase Connector/J
OceanBase Connector/J uses the standard Java Database Connectivity (JDBC) API to provide a driver for Java applications to connect to OceanBase Database.
Java Database Connectivity (JDBC) provides Java with an interface for connecting to relational databases and is a Java standard. The JDBC standard was defined by Sun Microsystems and is implemented through the standard
java.sqlinterface, which allows providers to implement and extend the standard with their own JDBC drivers. JDBC is a Call Level Interface (CLI) based on X/Open SQL.OceanBase Connector/J is a JDBC Type 4 driver, which communicates directly with the database engine over a native protocol. The Connector/J driver is compatible with the OB2.0 protocol.
OceanBase Database supports the OceanBase Connector/J driver and is fully compatible with the native MySQL JDBC driver (MySQL Connector Java). OceanBase Connector/J is fully compatible with the way MySQL JDBC is used, can automatically detect whether OceanBase Database runs in MySQL-compatible mode or Oracle-compatible mode, and is compatible with both modes at the protocol layer.
Note
OceanBase Database determines whether it is running in MySQL-compatible mode or Oracle-compatible mode based on the tenant name specified during the JDBC driver connection. Tenants in Oracle-compatible mode are only allowed to use SQL syntax that is compatible with Oracle.
In addition to the standard JDBC application programming interface (API), OceanBase Connector/J is also compatible with the way Oracle JDBC drivers are used. The Oracle-compatible mode of OceanBase is compatible with most Oracle syntax.
OceanBase Connector/J uses a one-click installation mode. The driver installation package is named
oceanbase-client-[version number].jar.To obtain the OceanBase Connector/J installation package, go to Resources > Download Center > Enterprise Edition > Drivers and Middleware on the OceanBase website and open OceanBase JDBC driver. Select the version you need, enter your information, and download the package. For detailed installation steps, see OceanBase Connector/J.
For a practical example of connecting a Java application to OceanBase Database, see Sample program for connecting to OceanBase Database with OceanBase Connector/J.
SpringJDBC
For a practical example of connecting to OceanBase Database with SpringJDBC, see Connect to OceanBase Database with SpringJDBC.
Java ORM frameworks
SpringBoot
For a practical example of connecting to OceanBase Database with SpringBoot, see Connect to OceanBase Database with SpringBoot.
SpringBatch
For a practical example of connecting to OceanBase Database with SpringBatch, see Connect to OceanBase Database with SpringBatch.
SpringDataJPA
For a practical example of connecting to OceanBase Database with SpringDataJPA, see Connect to OceanBase Database with SpringDataJPA.
Hibernate
For a practical example of connecting to OceanBase Database with Hibernate, see Connect to OceanBase Database with Hibernate.
MyBatis
For a practical example of connecting to OceanBase Database with MyBatis, see Connect to OceanBase Database with MyBatis.
Jfinal
For a practical example of connecting to OceanBase Database with Jfinal, see Connect to OceanBase Database with Jfinal.
Connection pool configuration
OceanBase Database supports multiple connection pool implementations. Choose the one that best fits your business requirements. The following table describes the features and use cases of each connection pool:
Connection pool |
Features |
Use cases |
|---|---|---|
| Druid | Comprehensive features, including monitoring and statistics | Enterprise applications that need to monitor and manage connection pools. |
| HikariCP | High performance and lightweight | High-concurrency applications that prioritize performance. |
| C3P0 | Mature and stable, with rich features | Traditional Java applications. |
| DBCP | An Apache project with flexible configuration | Scenarios that require integration with frameworks such as Spring. |
| Proxool | Supports connection pool monitoring | Applications that need to monitor connection status. |
| Tomcat | Built into the Tomcat container | Web applications. |
| Commons Pool | A general-purpose object pool implementation | Scenarios that require custom connection pool logic. |
Connection pool configuration recommendations
- Initial connections: 5 to 10.
- Maximum connections: Set this item based on the application load and database resources.
- Connection timeout: 30 seconds.
- Idle connection recycling time: 10 minutes.
- Validation query:
SELECT 1 FROM DUAL.
Monitoring and maintenance
- Check the connection pool status regularly to avoid connection leaks.
- Monitor connection wait times and the number of active connections.
- Adjust connection pool parameters dynamically based on the business load.
Connection pool implementation examples
OceanBase Database supports the following connection pool implementations. Click a link to view the detailed configuration example: