OceanBase logo

OceanBase

A unified distributed database ready for your transactional, analytical, and AI workloads.

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

A unified distributed database ready for your transactional, analytical, and AI workloads.

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.0

    Download PDF

    OceanBase logo

    The Unified Distributed Database for the AI Era.

    Follow Us
    Products
    OceanBase CloudOceanBase EnterpriseOceanBase Community EditionOceanBase seekdb
    Resources
    DocsBlogLive DemosTraining & Certification
    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.0
    iconOceanBase Database
    SQL - V 4.3.0
    SQL
    KV
    • 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

    Connect to OceanBase Database by using a Tomcat connection pool

    Last Updated:2025-12-02 02:51:29  Updated
    share
    What is on this page
    Prerequisites
    Procedure
    Step 1: Import the tomcat-mysql-client project into IntelliJ IDEA
    Step 2: Obtain the connection information of OceanBase Database
    Step 3: Modify the database connection information in the tomcat-mysql-client project
    Step 4: Set up the Tomcat runtime environment of the tomcat-mysql-client project
    Step 5: Run the tomcat-mysql-client project
    Project code introduction
    Code in the pom.xml file
    application.properties
    Code in the web.xml file
    Introduction to the UserConfig.java file
    UserController.java
    Introduction to the User.java file
    Full code
    References

    folded

    share

    This topic introduces how to build an application by using a Tomcat connection pool, OceanBase Connector/J, and OceanBase Database. It also covers the use of the application for fundamental database operations, including table creation, data insertion, data deletion, data updating, and data query.

    Download the tomcat-mysql-client sample project
    Connect to OceanBase Database by using a Tomcat connection pool (MySQL mode)

    Prerequisites

    • You have installed OceanBase Database.
    • You have installed JDK 1.8 and Maven.
    • You have installed IntelliJ IDEA.

    Note

    The tool used to run the sample code in this topic is IntelliJ IDEA 2021.3.2 (Community Edition). You can also choose a tool that suits your personal preference to run the code.

    Procedure

    Note

    The steps outlined in this topic are for the Windows environment. If you are using a different operating system or compiler, the steps may vary slightly.

    1. Import the tomcat-mysql-client project into IntelliJ IDEA.
    2. Obtain the connection information of OceanBase Database.
    3. Modify the database connection information in the tomcat-mysql-client project.
    4. Set up the Tomcat runtime environment of the tomcat-mysql-client project.
    5. Run the tomcat-mysql-client project.

    Step 1: Import the tomcat-mysql-client project into IntelliJ IDEA

    1. Start IntelliJ IDEA and choose File > Open....

      file

    2. In the Open File or Project window, select the project files and click OK to import the files.

    3. IntelliJ IDEA automatically recognizes the files and displays the project's directory structure, file list, module list, dependency relationships, and other details in the Project window. The Project window is typically positioned on the left side of the IntelliJ IDEA interface and is generally open by default. If the Project window is closed, you can reopen it by choosing View > Tool Windows > Project in the menu bar or by using the shortcut Alt + 1.

      Note

      When you import a project using IntelliJ IDEA, it will automatically detect the pom.xml file in the project, download the required dependency libraries based on the described dependencies in the file, and add them to the project.

    4. View the project.

      tomcat

    Step 2: Obtain the connection information of OceanBase Database

    1. Contact the deployment personnel or administrator of OceanBase Database to obtain the database connection string.

      obclient -hxx.xx.xx.xx -P2883 -uroot@sys#cluster -p**** -A
      
    2. Fill in the URL below based on the OceanBase Database connection string.

      Note

      The URL is required in the application.properties file.

      jdbc:oceanbase://host:port/schema_name?user=$user_name&password=$password&characterEncoding=UTF-8
      

      The parameters are described as follows:

      • host: the IP address for connecting to OceanBase Database. For connection through ODP, this parameter is the IP address of an ODP. For direct connection, this parameter is the IP address of an OBServer node.
      • port: the port for connecting to OceanBase Database. For connection through ODP, the default value is 2883, which can be customized when ODP is deployed. For direct connection, the default value is 2881, which can be customized when OceanBase Database is deployed.
      • schema_name: the name of the schema to be accessed.
      • user_name: the tenant account. For connection through ODP, the tenant account can be in the username@tenant name#cluster name or cluster name:tenant name:username format. For direction connection, the tenant account is in the username@tenant name format.
      • password: the password of the account.
      • characterEncoding: the character encoding format for the URL of the database. Default value: utf8.

    For more information about URL parameters, see Database URL.

    Step 3: Modify the database connection information in the tomcat-mysql-client project

    Modify the database connection information in the application.properties file based on the information obtained in Step 2: Obtain the connection information of OceanBase Database.

    Here is an example:

    • The name of the database driver is: com.oceanbase.jdbc.Driver.
    • The IP address of the OBServer node is 10.10.10.1.
    • The port is 2881.
    • The name of the database to be accessed is TEST.
    • The tenant account is root@xymysql. xymysql is a MySQL user tenant created in OceanBase Database, and root is the username of the xymysql tenant.
    • The password is ******.

    The sample code is as follows:

    #Apache Commons DBCP2 Connection Pool
    #Database Connection Pool Driver Class Name
    db.app.pool.driverClassName=com.oceanbase.jdbc.Driver
    #Database URL
    db.app.pool.url=jdbc:oceanbase://10.10.10.1/TEST?characterEncoding=UTF-8
    #Database username
    db.app.pool.username=root@xymysqll
    #Database password
    db.app.pool.password=******
    #Initial size of connection pool
    db.app.pool.initialSize=3
    #Maximum number of connections in the connection pool
    db.app.pool.maxTotal=10
    #Maximum number of idle connections in the connection pool
    db.app.pool.maxIdle=20
    #Minimum number of idle connections in the connection pool
    db.app.pool.minIdle=5
    #Maximum wait time for obtaining connections (in milliseconds)
    db.app.pool.maxWaitMillis=5000
    #Verify the connection's query statement
    db.app.pool.validationQuery=select 1 from dual
    

    Step 4: Set up the Tomcat runtime environment of the tomcat-mysql-client project

    1. Download Tomcat 8.5.95.

      Download the compressed file of Tomcat 8.5.95 from the official website of Apache Tomcat and decompress it to the installation directory.

    2. Configure Tomcat in IntelliJ IDEA.

      Open IntelliJ IDEA and choose File > Settings > Plugins. In the search box in the middle of the Settings window, search for Smart Tomcat, download it, and then choose Apply. The Tomcat Server page will appear at the bottom of the Settings window. Go to the Tomcat Server page and click + on the right side to browse and select the decompressed Tomcat. Then click Apply and OK. The Tomcat configuration is completed.

      Tomcat server

    3. Create a Tomcat run configuration.

      In the top toolbar of IntelliJ IDEA, choose Run > Edit Configurations. In the Run/Debug Configurations window, click + and select Tomcat Server. Set the name of the server Name, choose Tomcat sever from the Configuration drop-down list and modify the value of Context path to /. Set the value of SSL port to 8080. Click + in the Before launch section and select Launch Web Browser. Click Edit and set the URL to http://localhost:8080/hello/getData. Click Apply and then OK.

      apache tomcat8.5.95

    4. Run the Tomcat server.

      In the top toolbar of IDEA, select the Tomcat run configuration you just created. Click the run button green triangle to start the Tomcat server. You can view the startup logs of the Tomcat server in the Run window of IDEA.

    Step 5: Run the tomcat-mysql-client project

    1. Determine the running path.

      In the top toolbar of IDEA, select the Tomcat run configuration that you created earlier. Click the green triangle to start the Tomcat server. In the Chrome or IE browser, open the http://localhost:8080/hello/getData path to view the running result.

    2. View the running result.

      In the console window of IDEA, view the logs and output results of the project.

      • The result after data is inserted.

        tomcat connection pool test0
        tomcat connection pool test1
        tomcat connection pool test2
        tomcat connection pool test3
        tomcat connection pool test4
        tomcat connection pool test5
        tomcat connection pool test6
        tomcat connection pool test7
        tomcat connection pool test8
        tomcat connection pool test9
        
      • The result after data is modified.

        -----After modification-----
        POOl connection pool test0
        POOl connection pool test1
        POOl connection pool test2
        POOl connection pool test3
        POOl connection pool test4
        POOl connection pool test5
        POOl connection pool test6
        POOl connection pool test7
        POOl connection pool test8
        POOl connection pool test9
        
      • The result returned to the web interface.

        Web

    Project code introduction

    Click tomcat-mysql-client to download the project code, which is a compressed file named tomcat-mysql-client.

    After decompressing it, you will find a folder named tomcat-mysql-client. The directory structure is as follows:

    │--pom.xml
    │
    ├─.idea
    │
    ├─src
    │  ├─main
    │  │  ├─java
    │  │  │  └─com
    │  │  │      └─oceanbase
    │  │  │          └─testtomcat
    │  │  │              ├─config
    │  │  │              │   └─UserConfig.java
    │  │  │              │
    │  │  │              ├─controller
    │  │  │              │   └─UserController.java
    │  │  │              │
    │  │  │              └─pojo
    │  │  │                  └─User.java
    │  │  │
    │  │  ├─resources
    │  │  │    └─application.properties
    │  │  │    
    │  │  └─webapp    
    │  │      └─WEB-INF
    │  │          └─web.xml
    │  │             
    │  │                
    │  │
    │  └─test
    │      └─java
    │         
    │
    └─target
    

    Here is a breakdown of the files and directories:

    • pom.xml: the configuration file of the Maven project, which contains the dependencies, plug-ins, and build details of the project.
    • .idea: the directory for storing project-related configuration information used in the Integrated Development Environment (IDE).
    • src: the directory for storing the source code in the project.
    • main: the directory for storing the main source code and resource files.
    • java: the directory for storing the Java source code.
    • com: the root directory for storing the Java package.
    • oceanbase: the root directory for storing the project.
    • testtomcat: the directory for storing code of the JFinal framework.
    • config: the directory for storing configuration files, including those of the application.
    • UserConfig.java: the user configuration file.
    • controller: the controller directory for storing the controller file of the application.
    • UserController.java: the controller file.
    • pojo: the directory for storing JavaBean or entity classes.
    • User.java: a file for storing user entity classes.
    • resources: the directory for storing resource files, such as configuration files and SQL files.
    • application.properties: the configuration file for storing database connection information.
    • webapp: the directory for storing the static resources and configuration file of the web application.
    • WEB-INF: the directory for storing the configuration file and other protected resource files of the web application.
    • web.xml: the deployment descriptor file of the web application.
    • test: the directory for storing the test code and resource files.
    • target: the directory for storing compiled class files and .jar packages.

    Code in the pom.xml file

    Note

    If you only want to verify the example, use the default code without making any modifications. Alternatively, you can modify the pom.xml file to suit your specific requirements.

    The pom.xml configuration file is as follows:

    1. Declaration statement.

      Declare this file to be an XML file that uses XML standard 1.0 and character encoding UTF-8.

      **The sample code is as follows: **

      <?xml version="1.0" encoding="UTF-8"?>
      
    2. Configure the namespaces and the POM model version in the POM.

      1. Use xmlns to set the POM's namespace to http://maven.apache.org/POM/4.0.0.
      2. Use xmlns:xsi to set the XML namespace to http://www.w3.org/2001/XMLSchema-instance.
      3. Use xsi:schemaLocation to set the POM's namespace to http://maven.apache.org/POM/4.0.0, and the URI of the corresponding XSD file to http://maven.apache.org/xsd/maven-4.0.0.xsd.
      4. Use the <modelVersion> element to set the POM model version used by the POM file to 4.0.0.

      The sample code is as follows:

      <project xmlns="http://maven.apache.org/POM/4.0.0"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
       <modelVersion>4.0.0</modelVersion>
      </project>
      
    3. Configure basic information.

      1. Set the project group ID to com.oceanbase by using <groupId>.
      2. Set the project dependency to tomcat-mysql-client by using <artifactId>.
      3. Set the project version to 1.0-SNAPSHOT by using <version>.
      4. Set the packaging mode of the project to WAR file (Web application archive) by using <packaging>.

      The sample code is as follows:

       <groupId>com.oceanbase</groupId>
       <artifactId>tomcat-mysql-client</artifactId>
       <version>1.0-SNAPSHOT</version>
       <!-- Packaging method (default to jar) -->
       <packaging>war</packaging>
      
    4. Configure the Maven version.

      The <maven.compiler.source> and <maven.compiler.target> parameters are set to Java 8, which specifies both the source code version and target code version of the compiler.

      The sample code is as follows:

       <properties>
           <maven.compiler.source>8</maven.compiler.source>
           <maven.compiler.target>8</maven.compiler.target>
       </properties>
      
    5. Configure core dependencies.

      1. Specify the dependency group as com.jfinal, the dependency name as jfinal, and the dependency version as 5.0.6. With this dependency, you can use the features of the JFinal framework.

        **The sample code is as follows: **

        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jfinal</artifactId>
            <version>5.0.6</version>
        </dependency>
        
      2. Specify the dependency group as com.alibaba, the dependency name as druid, and the dependency version as 1.2.8. With this dependency, you can use the Druid library to manage and optimize the establishment and release of database connections.

        The sample code is as follows:

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.2.8</version>
        </dependency>
        
      3. Specify the dependency group as org.apache.commons, the dependency name as commons-dbcp2, and the dependency version as 2.9.0. With this dependency, you can use the Apache Commons DBCP2 library to manage and optimize the establishment and release of database connections.

        The sample code is as follows:

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-dbcp2</artifactId>
            <version>2.9.0</version>
        </dependency>
        
      4. Specify the dependency group as mysql, the dependency name as mysql-connector-java, and the dependency version as 5.1.40. With this dependency, you can use the client features such as connections, queries, and transactions provided by OceanBase Database.

        The sample code is as follows:

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.40</version>
        </dependency>
        

    application.properties

    The application.properties file configures the connection information for connecting to OceanBase Database. It includes the class name of the database driver, the URL, the username, the password, and the connection pool configurations. These configurations are used in the application to obtain and manage database connections for database operations.

    • Set the database driver to com.mysql.jdbc.Driver by specifying db.app.pool.driverClassName so that you can connect to OceanBase Database.

    • Specify the URL of connecting to the database by using db.app.pool.url.

    • Specify the username of connecting to the database by using db.app.pool.username.

    • Specify the password of connecting to the database by using db.app.pool.password.

    • Set the initial size of the connection pool to 3 by specifying db.app.pool.initialSize, which means that 3 database connections are created when the pool starts.

    • Set the maximum size of the connection pool to 10 by specifying db.app.pool.maxTotal, which means that at most 10 database connections can be created in the pool.

    • Set the maximum number of idle connections in the pool to 20 by specifying db.app.pool.maxIdle.

    • Set the minimum number of idle connections in the pool to 5 by specifying db.app.pool.minIdle.

    • Set the timeout period for obtaining a database connection to 5000ms by specifying db.app.pool.maxWaitMillis, which means that if a connection cannot be obtained within 5000ms, a timeout exception is thrown.

    • Specify the SQL verification query statement select 1 by using db.app.pool.validationQuery, which means that when a connection is obtained from the pool, the system executes this query statement to verify the validity of the connection.

      The sample code is as follows:

        #Apache Commons DBCP2 Connection Pool
        #Database Connection Pool Driver Class Name
        db.app.pool.driverClassName=com.mysql.jdbc.Driver
        #Database URL
        db.app.pool.url=jdbc:mysql:////host:port/schema_name?characterEncoding=UTF-8
        #Database username
        db.app.pool.username=user_name
        #Database password
        db.app.pool.password=******
        #Initial size of connection pool
        db.app.pool.initialSize=3
        #Maximum number of connections in the connection pool
        db.app.pool.maxTotal=10
        #Maximum number of idle connections in the connection pool
        db.app.pool.maxIdle=20
        #Minimum number of idle connections in the connection pool
        db.app.pool.minIdle=5
        #Maximum wait time for obtaining connections (in milliseconds)
        db.app.pool.maxWaitMillis=5000
        #Verify the connection's query statement
        db.app.pool.validationQuery=select 1 
      

    Common configurations for the DBCP connection pool in Tomcat:

    Notice

    The specific attribute (parameter) configurations depend on the project requirements and database characteristics. We recommend that you configure the attributes based on the actual situation.

    Attribute Default value Description
    username N/A The username for connecting to the database.
    password N/A The password for connecting to the database.
    url N/A The URL for connecting to the database.
    driverClassName N/A The standard Java class name of the database driver.
    connectionProperties N/A The connection properties that are sent to the JDBC driver when a new connection is established. The properties are in the [propertyName=property;] format.
    defaultAutoCommit driver default The default auto-commit status for connections created by the connection pool. If this attribute is not set, the setAutoCommit method is not called.
    defaultReadOnly driver default The default read-only status for connections created by the connection pool. If this attribute is not set, the setReadOnly method is not called.
    defaultTransactionIsolation driver default The default transaction isolation level for connections created by the connection pool.
    defaultCatalog N/A The default connection catalog for connections created by the connection pool.
    cacheState true Specifies whether to cache the readOnly and autoCommit settings of connections. If set to True, the readOnly and autoCommit settings of connections are cached after the first read or write operation and before subsequent write operations on the connections. This eliminates the need for additional database queries when calling getter methods.
    defaultQueryTimeout null The query timeout period in seconds for statements created by connections in the pool. If a positive value is specified for this attribute, the specified value is passed to the setQueryTimeout method of the driver's Statement. If null is specified, the default value of the driver is used.
    enableAutoCommitOnReturn true Specifies whether to check and configure the auto-commit status of a connection before it is returned to the pool.
    rollbackOnReturn true Specifies whether to roll back a non-read-only connection that has auto-commit disabled when it is returned to the pool. If set to True, a connection that has auto-commit disabled and is not read-only is rolled back when it is returned to the pool.
    initialSize 0 The initial number of connections created when the pool starts.
    maxTotal 8 The maximum number of active connections allocated from the pool.
    maxIdle 8 The maximum number of idle connections retained in the pool. A negative value specifies no limit.
    minIdle 0 The minimum number of idle connections retained in the pool. A value of 0 specifies not to create connections.
    maxWaitMillis indefinitely The maximum milliseconds to wait for a connection to be returned from the pool when it is unavailable. The value -1 specifies to wait indefinitely.
    validationQuery N/A The SQL verification query statement. If this attribute is specified, the specified statement must be an SQL SELECT statement that returns at least one row; otherwise, the connection will be verified by calling the isValid method.
    validationQueryTimeout no timeout The timeout period in seconds for a verification query to fail. The unit is seconds. If a positive value is specified for this attribute, the specified value is passed to the setQueryTimeout method of the driver's Statement.
    testOnCreate false Specifies whether to verify an object after it is created. If the object cannot be verified, the object creation attempt will fail.
    testOnBorrow true Specifies whether to verify an object before it is borrowed from the pool. If the object cannot be verified, the object will be deleted from the pool and another object will be borrowed.
    testOnReturn false Specifies whether to verify an object before it is returned to the pool.
    testWhileIdle false Specifies whether to verify an idle object by using the idle object evictor. If the object cannot be verified, it will be deleted from the pool.
    timeBetweenEvictionRunsMillis -1 The number of milliseconds the idle object evictor thread sleeps between runs. When this attribute is set to a positive value, the idle object evictor thread runs periodically; when it is set to a negative value, the idle object evictor thread does not run.
    numTestsPerEvictionRun 3 The number of objects checked during each run of the idle object evictor thread.
    minEvictableIdleTimeMillis 1000 * 60 * 30 The minimum idle time in milliseconds of an object in the pool.
    softMinEvictableIdleTimeMillis -1 The minimum idle time in milliseconds of an object in the pool, including the effect of the MinIdle attribute. A negative value specifies not to set a minimum idle time.
    maxConnLifetimeMillis -1 The maximum lifetime in milliseconds of a connection. A connection whose lifetime exceeds this attribute's value cannot be reactivated, idled, or verified. A value of 0 or a negative value specifies an unlimited lifetime.
    logExpiredConnections true Specifies whether to record connections that are closed due to exceeding the maximum lifetime. The value false specifies to disable the recording of expired connection logs.
    connectionInitSqls null The SQL statements that initialize the connection when it is first created. These statements are executed only when the connection factory creates connections.
    lifo true Specifies whether the borrowObject method returns the most recently used connection in the pool. If set to True, the borrowObject method returns the last in connection (if available) in the pool; if set to False, connections are returned to the pool in the order of their return, and the idle connection pool functions as a FIFO queue.
    poolPreparedStatements false Specifies whether to enable the prepared statement pool.
    maxOpenPreparedStatements unlimited The maximum number of open statements allocated from the pool. A negative value specifies no limit.
    accessToUnderlyingConnectionAllowed false Specifies whether to allow access to the underlying connection.
    removeAbandonedOnMaintenance false Specifies whether to delete abandoned connections during pool maintenance. If set to True, abandoned connections are deleted when maintenance is completed. If this attribute is not set, the maintenance feature is not enabled and this attribute does not take effect.
    removeAbandonedOnBorrow false Specifies whether to delete abandoned connections when a connection is borrowed from the pool. If set to True, abandoned connections are deleted each time a connection is borrowed from the pool. In addition, the following requirements must be met:
    • getNumActive() > getMaxTotal() - 3
    • getNumIdle() < 2
    removeAbandonedTimeout 300 The timeout period in seconds for deleting an abandoned connection. The unit is seconds. This attribute specifies the longest idle time of a connection before it can be deleted as abandoned.
    logAbandoned false Specifies whether to record stack traces of application code that causes connections to be abandoned. Stack traces must be generated, and therefore recording abandoned statements and connections increases the overhead of each connection opening or new statement execution.
    abandonedUsageTracking false Specifies whether to record stack traces of abandoned connections. If set to True, stack traces of connections are recorded each time the connections are used, and the recorded stack traces of the connections are retained to help debug abandoned connections. This setting increases a great amount of overhead.
    fastFailValidation false Specifies whether to immediately fail the validation request of a connection that throws a fatal SQLException. If set to True, the validation request of a connection is immediately failed when the connection is disconnected, without calling the isValid method of the driver's Statement or executing a verification query. By default, the following SQL_STATE codes are considered to be fatal errors:
    • 57P01 (shutdown by administrator)
    • 57P02 (crash shutdown)
    • 57P03 (cannot connect now)
    • 01002 (SQL92 disconnect error)
    • JZ0C0 (Sybase disconnect error)
    • JZ0C1 (Sybase disconnect error)
    • Any SQL_STATE code that starts with 08
    To override the default set of disconnect codes, set the disconnectionSqlCodes attribute.
    disconnectionSqlCodes null A comma-separated list of SQL_STATE codes. These codes are considered to be fatal disconnect errors. When the fastFailValidation attribute is set to True, the disconnectionSqlCodes attribute takes effect.
    jmxName N/A The name under which the data source is registered as a JMX MBean. The name must follow the JMX object name syntax (for more information, see javadoc).

    Code in the web.xml file

    The web.xml file is used to configure filters for web applications.

    The content of the web.xml configuration file is as follows:

    1. The declaration statement.

      Declare this file to be an XML file that uses XML standard 1.0 and character encoding UTF-8.

      The sample code is as follows:

      <?xml version="1.0" encoding="UTF-8"?>
      
    2. The configuration of the XML namespace and the XML model version.

      1. Use xmlns:xsi to set the XML namespace to http://www.w3.org/2001/XMLSchema-instance.
      2. Use xmlns to set the XML namespace to http://java.sun.com/xml/ns/javaee.
      3. Use xsi:schemaLocation to set the XML namespace to http://java.sun.com/xml/ns/javaee, and the URI of the corresponding XSD file to http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd.
      4. Use <id> and <version> to set the ID of the web application to WebApp_ID and the version number to 3.0.

      The sample code is as follows:

       <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="http://java.sun.com/xml/ns/javaee" 
                xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
                id="WebApp_ID" 
                version="3.0">
      
    3. The configuration of a JFinal filter.

      Configure a filter named jfinal for the web application to use the JFinal framework. Set the class of the filter to com.jfinal.core.JFinalFilter. Use the initialization parameter configClass to set the location of the configuration class of the JFinal framework to com.oceanbase.testtomcat.config.UserConfig. The JFinal filter allows you to use the JFinal framework in the web application and configure the behavior of the JFinal framework based on the specified configuration class.

      The sample code is as follows:

       <filter>
           <filter-name>jfinal</filter-name>
           <filter-class>com.jfinal.core.JFinalFilter</filter-class>
           <init-param>
               <param-name>configClass</param-name>
               <!-- your jfinal configuration location -->
               <param-value>com.oceanbase.testtomcat.config.UserConfig</param-value>
           </init-param>
       </filter>
      
    4. The configuration of mappings of the JFinal filter.

      Apply the jfinal filter to all request paths, namely, to all requests in the application.

      The sample code is as follows:

       <filter-mapping>
           <filter-name>jfinal</filter-name>
           <url-pattern>/*</url-pattern>
       </filter-mapping>
      

    Introduction to the UserConfig.java file

    The UserConfig.java file is used to configure the routing, plug-ins, database connections, and other related information of an application.

    The code in the UserConfig.java file mainly includes the following parts:

    1. Reference other classes and APIs.

      Declare the current file to contain the following APIs and classes:

      • StatFilter class: used to count the performance of database access.
      • JdbcConstants class: used to define constant values of database types.
      • WallFilter class: used to prevent SQL injection attacks.
      • PropKit class: used to read configuration files.
      • ActiveRecordPlugin class: used to operate databases.
      • Db class: used to execute database operations.
      • MysqlDialect class: used to specify the dialect of the database.
      • DruidPlugin class: used to connect to databases.
      • Engine class: used to configure template engines.
      • UserController class: used to process user-related requests.
      • User class: used to transmit and store user data.

      The sample code is as follows:

      import com.alibaba.druid.filter.stat.StatFilter;
      import com.alibaba.druid.util.JdbcConstants;
      import com.alibaba.druid.wall.WallFilter;
      import com.jfinal.config.*;
      import com.jfinal.kit.PropKit;
      import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
      import com.jfinal.plugin.activerecord.Db;
      import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
      import com.jfinal.plugin.druid.DruidPlugin;
      import com.jfinal.template.Engine;
      import com.oceanbase.testjfinal.controller.UserController;
      import com.oceanbase.testjfinal.pojo.User;
      
    2. Define the UserConfig class.

      You can rewrite the methods of the JFinalConfig class to configure the constants, routing, plug-ins, and database connections.

      1. Define the configConstant method.

        Use this method to configure the constants of the JFinal framework and read the configuration values from the configuration file by using PropKit.

        The sample code is as follows:

        @Override
        public void configConstant(Constants constants) {
            PropKit.use("application.properties");
        }
        
      2. Define the configRoute method.

        Use this method to configure the routing mappings. Use the routes.add method to map the "/hello" path to the default access page of the UserController class.

        The sample code is as follows:

        @Override
        public void configRoute(Routes routes) {
            routes.add("/hello", UserController.class, "/");
        }
        
      3. Define the configEngine method.

        Use this method to configure the template engine.

        The sample code is as follows:

        @Override
        public void configEngine(Engine engine) {
        }
        
      4. Define the configPlugin method.

        Use this method to configure plug-ins of the application. Call the init method to initialize the database connection and table structure, create the DruidPlugin and ActiveRecordPlugin plug-ins, and add them to the plugins collection. Additionally, call the addMapping method of the activeRecordPlugin to add mappings between database tables and entity classes. In this way, the TEST_USER table is mapped to the User class.

        The sample code is as follows:

        @Override
        public void configPlugin(Plugins plugins) {
            init();
            DruidPlugin druidPlugin = createDruidPlugin();
            plugins.add(druidPlugin);
        
            ActiveRecordPlugin activeRecordPlugin = createActiveRecordPlugin(druidPlugin);
            activeRecordPlugin.addMapping("TOMCAT_TEST", User.class);
            plugins.add(activeRecordPlugin);
        }
        
      5. Define the createDruidPlugin method.

        Use this method to create a DruidPlugin plug-in and configure the relevant parameters, such as the size of the connection pool, SQL firewall, and error handling for connections.

        • Call the get method of PropKit to obtain the database connection-related attribute values from the configuration file. The attribute values include the URL, username, password, and driver class. Then create a DruidPlugin object and initialize it with the attribute values.

        • Call the addFilter method to add a StatFilter instance to the DruidPlugin for performance statistics of database access. Create a WallFilter instance, set the database type to OceanBase by calling the setDbType method, and add the WallFilter instance to the DruidPlugin for SQL firewall filtering.

        • Call the setInitialSize method to set the initial size of the connection pool; the setMaxPoolPreparedStatementPerConnectionSize method to set the maximum number of preprocessed statements per connection in the pool; the setTimeBetweenConnectErrorMillis method to set the time interval between two connection errors; and the setValidationQuery method to set the validation query statement for connections. Finally, return the created DruidPlugin instance.

          The sample code is as follows:

          private DruidPlugin createDruidPlugin() {
              DruidPlugin druidPlugin = new DruidPlugin(
                  PropKit.get("db.app.pool.url"),
                  PropKit.get("db.app.pool.username"),
                  PropKit.get("db.app.pool.password"),
                  PropKit.get("db.app.pool.driverClassName")
              );
          
              druidPlugin.addFilter(new StatFilter());
              WallFilter wallFilter = new WallFilter();
              wallFilter.setDbType(JdbcConstants.OCEANBASE);
              druidPlugin.addFilter(wallFilter);
          
              druidPlugin.setInitialSize(PropKit.getInt("db.app.pool.initialSize"));
              druidPlugin.setMaxPoolPreparedStatementPerConnectionSize(PropKit.getInt("db.app.pool.maxTotal"));
              druidPlugin.setTimeBetweenConnectErrorMillis(PropKit.getInt("db.app.pool.maxWaitMillis"));
              druidPlugin.setValidationQuery("select 1");
          
              return druidPlugin;
          }
          
      6. Define the init method.

        Use this method to initialize database connections and create database tables. Call the initDbConnection method to initialize database connections and return an ActiveRecordPlugin instance. Then execute an SQL statement to query whether the TOMCAT_TEST table exists in the database. If the TOMCAT_TEST table exists, execute the SQL statement DROP TABLE TOMCAT_TEST to drop the table. Next, execute the CREATE TABLE statement to create a database table named TOMCAT_TEST. The table contains the ID and USERNAME fields. Finally, disconnect from the ActiveRecordPlugin plug-in and release the database connections.

        The sample code is as follows:

        public void init() {
            ActiveRecordPlugin arp = initDbConnection();
        
            // Check if table exists
            boolean tableExists = Db.queryInt("SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'TEST' AND TABLE_NAME = 'TOMCAT_TEST'") > 0;
        
            // Drop table if it exists
            if (tableExists) {
                Db.update("DROP TABLE TOMCAT_TEST");
            }
        
            // Create table
            String sql = "CREATE TABLE TOMCAT_TEST (ID int, USERNAME varchar(50))";
            Db.update(sql);
        
            arp.stop();
        }
        
      7. Define the initDbConnection method.

        Use this method to initialize database connections. First, call the createDruidPlugin method to create a DruidPlugin object and assign it to the druidPlugin variable. This method is responsible for creating and configuring the DruidPlugin object for managing the database connection pool. Then call the createActiveRecordPlugin method to create an ActiveRecordPlugin object and pass the druidPlugin object as a parameter to the method. This method is responsible for creating and configuring the ActiveRecordPlugin object for managing database operations. After that, call the druidPlugin.start method to start the DruidPlugin and initialize the database connection pool. Finally, call the activeRecordPlugin.start method to start the ActiveRecordPlugin. This method will initialize the relevant database operation settings based on the configurations.

        The sample code is as follows:

        private ActiveRecordPlugin initDbConnection() {
            DruidPlugin druidPlugin = createDruidPlugin();
            ActiveRecordPlugin activeRecordPlugin = createActiveRecordPlugin(druidPlugin);
        
            druidPlugin.start();
            activeRecordPlugin.start();
        
            return activeRecordPlugin;
        }
        
      8. Define the ConfigInterceptor and ConfigHandler methods.

        Use these methods to perform global configurations during the initialization of the system.

        The sample code is as follows:

        @Override
        public void configInterceptor(Interceptors interceptors) {
        }
        
        @Override
        public void configHandler(Handlers handlers) {
        }
        

    UserController.java

    The UserController.java file uses the getData method to insert data into the database, query data from the database, and return the query result to the client in the JSON format. Use the Db class of the JFinal framework for database operations, and use the custom User class for data mappings so as to return data.

    The code in the UserController.java file mainly includes the following parts:

    1. Reference other classes and APIs.

      Declare this file to contain the following APIs and classes:

      • Controller class: processes requests and responses.
      • Db class: executes database operations.
      • Record class: performs database operations, such as querying, inserting, updating, and deleting data.
      • ArrayList class: creates an empty list.
      • User class: maps database tables.
      • List API: operates the query result set.

      The sample code is as follows:

      import com.jfinal.core.Controller;
      import com.jfinal.plugin.activerecord.Db;
      import com.jfinal.plugin.activerecord.Record;
      
      import java.util.ArrayList;
      import java.util.List;
      
    2. Define the UserController class.

      Use this class to provide a controller for the JFinal framework, and use the getData method to insert data into and query data from the database.

      1. Insert data. Create a dataList list that contains 10 Record objects. Each Record object has unique ID and USERNAME values. Use the Db.batchSave method to save the dataList list to a database table named TOMCAT_TEST.

        The sample code is as follows:

                for (int i = 0; i < 10; i++) {
                    Record record = new Record().set("ID", i).set("USERNAME", "Tomcat connection pool test" + i);
                    dataList.add(record);
                }
                Db.batchSave("TOMCAT_TEST", dataList, dataList.size());
        
      2. Query data. Use the Db.find method to execute an SQL query and store the query result in the resultList list. Use an enhanced FOR loop to traverse each Record object in the resultList list. Use the getStr method to obtain values of specified fields in a Record object and use the System.out.println method to return these values.

        The sample code is as follows:

            List<Record> resultList = Db.find("SELECT * FROM TOMCAT_TEST");
            for (Record result : resultList) {
                System.out.println(result.getStr("USERNAME"));
            }
        
      3. Modify data. Use a loop to perform 10 rounds of iterations and execute an update statement in each iteration. Call the Db.update method to update records in the TOMCAT_TEST table based on specified conditions.

        The sample code is as follows:

            for (int i = 0; i < 10; i++) {
                Db.update("UPDATE TOMCAT_TEST SET USERNAME = 'Connection pool test" + i + "' WHERE ID = " + i);
            }
        
      4. Query the modified data. Query the TOMCAT_TEST table and save the query result in modifiedList. Return the information in the -----After modification----- section. Traverse modifiedList and return the USERNAME value of each record. Use the renderJson method to render the response message Data retrieved successfully into the JSON format and return it to the client.

        The sample code is as follows:

                List<Record> modifiedList = Db.find("SELECT * FROM TOMCAT_TEST");
                System.out.println("-----After modification-----");
                for (Record modified : modifiedList) {
                    System.out.println(modified.getStr("USERNAME"));
                }
                renderJson("Data retrieved successfully");
        

    Introduction to the User.java file

    The User.java file is used to map database tables and Java objects.

    The code in the User.java file mainly includes the following parts:

    1. Reference the Model class.

      The Model class is used to map database tables and operate data.

    2. Define the User class.

      The User class inherits the methods provided in the Model class for database operations.

      The sample code is as follows:

      import com.jfinal.plugin.activerecord.Model;
      
      
          public class User extends Model<User> {
              public static final User dao = new User();
      }
      

    Full code

    pom.xml
    application.properties
    web.xml
    UserConfig.java
    UserController.java
    User.java
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.oceanbase</groupId>
        <artifactId>tomcat-mysql-client</artifactId>
        <version>1.0-SNAPSHOT</version>
        <!-- Packaging method (default to jar) -->
        <packaging>war</packaging>
    
        <properties>
            <maven.compiler.source>8</maven.compiler.source>
            <maven.compiler.target>8</maven.compiler.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>com.jfinal</groupId>
                <artifactId>jfinal</artifactId>
                <version>5.0.6</version>
            </dependency>
    
    
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.2.8</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-dbcp2</artifactId>
                <version>2.9.0</version>
            </dependency>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.40</version>
                </dependency>
    
        </dependencies>
    </project>
    
        #Apache Commons DBCP2 Connection Pool
        #Database Connection Pool Driver Class Name
        db.app.pool.driverClassName=com.mysql.jdbc.Driver
        #Database URL
        db.app.pool.url=jdbc:mysql:////host:port/schema_name?characterEncoding=UTF-8
        #Database username
        db.app.pool.username=user_name
        #Database password
        db.app.pool.password=******
        #Initial size of connection pool
        db.app.pool.initialSize=3
        #Maximum number of connections in the connection pool
        db.app.pool.maxTotal=10
        #Maximum number of idle connections in the connection pool
        db.app.pool.maxIdle=20
        #Minimum number of idle connections in the connection pool
        db.app.pool.minIdle=5
        #Maximum wait time for obtaining connections (in milliseconds)
        db.app.pool.maxWaitMillis=5000
        #Verify the connection's query statement
        db.app.pool.validationQuery=select 1
    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
        <filter>
            <filter-name>jfinal</filter-name>
            <filter-class>com.jfinal.core.JFinalFilter</filter-class>
            <init-param>
                <param-name>configClass</param-name>
                <!-- your jfinal configuration location -->
                <param-value>com.oceanbase.testjfinal.config.UserConfig</param-value>
            </init-param>
        </filter>
    
        <filter-mapping>
            <filter-name>jfinal</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    </web-app>
    
    package com.oceanbase.testtomcat.config;
    
    import com.alibaba.druid.filter.stat.StatFilter;
    import com.alibaba.druid.util.JdbcConstants;
    import com.alibaba.druid.wall.WallFilter;
    import com.jfinal.config.*;
    import com.jfinal.kit.PropKit;
    import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
    import com.jfinal.plugin.activerecord.Db;
    import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
    import com.jfinal.plugin.druid.DruidPlugin;
    import com.jfinal.template.Engine;
    import com.oceanbase.testtomcat.controller.UserController;
    import com.oceanbase.testtomcat.pojo.User;
    
    public class UserConfig extends JFinalConfig {
        @Override
        public void configConstant(Constants constants) {
            // Read properties configuration
            PropKit.use("application.properties");
        }
    
        @Override
        public void configRoute(Routes routes) {
            // Set the default access page for project startup, which does not need to be set in the web.
            routes.add("/hello", UserController.class);
    
        }
    
        @Override
        public void configEngine(Engine engine) {
        }
    
        @Override
        public void configPlugin(Plugins plugins) {
            init();
            DruidPlugin druidPlugin = createDruidPlugin();
            plugins.add(druidPlugin);
    
            ActiveRecordPlugin activeRecordPlugin = createActiveRecordPlugin(druidPlugin);
            activeRecordPlugin.addMapping("TOMCAT_TEST", User.class);
            plugins.add(activeRecordPlugin);
        }
    
        private DruidPlugin createDruidPlugin() {
            DruidPlugin druidPlugin = new DruidPlugin(
                    PropKit.get("db.app.pool.url"),
                    PropKit.get("db.app.pool.username"),
                    PropKit.get("db.app.pool.password"),
                    PropKit.get("db.app.pool.driverClassName")
            );
    
            druidPlugin.addFilter(new StatFilter());
            WallFilter wallFilter = new WallFilter();
            wallFilter.setDbType(JdbcConstants.OCEANBASE);
            druidPlugin.addFilter(wallFilter);
    
            druidPlugin.setInitialSize(PropKit.getInt("db.app.pool.initialSize"));
            druidPlugin.setMaxPoolPreparedStatementPerConnectionSize(PropKit.getInt("db.app.pool.maxTotal"));
            druidPlugin.setTimeBetweenConnectErrorMillis(PropKit.getInt("db.app.pool.maxWaitMillis"));
            druidPlugin.setValidationQuery("select 1 from dual");
    
            return druidPlugin;
        }
    
        private ActiveRecordPlugin createActiveRecordPlugin(DruidPlugin druidPlugin) {
            ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(druidPlugin);
            activeRecordPlugin.setDialect(new MysqlDialect());
    
            return activeRecordPlugin;
        }
    
        public void init() {
            ActiveRecordPlugin arp = initDbConnection();
    
            // Check if table exists
            boolean tableExists = Db.queryInt("SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA = 'TEST' AND TABLE_NAME = 'TOMCAT_TEST'") > 0;
    
            // Drop table if it exists
            if (tableExists) {
                Db.update("DROP TABLE TOMCAT_TEST");
            }
    
            // Create table
            String sql = "CREATE TABLE TOMCAT_TEST (ID int, USERNAME varchar(50))";
            Db.update(sql);
    
            arp.stop();
        }
        private ActiveRecordPlugin initDbConnection() {
            DruidPlugin druidPlugin = createDruidPlugin();
            ActiveRecordPlugin activeRecordPlugin = createActiveRecordPlugin(druidPlugin);
    
            druidPlugin.start();
            activeRecordPlugin.start();
    
            return activeRecordPlugin;
        }
    
        @Override
        public void configInterceptor(Interceptors interceptors) {
        }
    
        @Override
        public void configHandler(Handlers handlers) {
        }
    }
    
    package com.oceanbase.testtomcat.controller;
    
    import com.jfinal.core.Controller;
    import com.jfinal.plugin.activerecord.Db;
    import com.jfinal.plugin.activerecord.Record;
    
    import java.util.ArrayList;
    import java.util.List;
    
    public class UserController extends Controller {
    
        public void getData() {
            try {
                List<Record> dataList = new ArrayList<>();
                // Insert data
                for (int i = 0; i < 10; i++) {
                    Record record = new Record().set("ID", i).set("USERNAME", "Tomcat connection pool test" + i);
                    dataList.add(record);
                }
                Db.batchSave("TOMCAT_TEST", dataList, dataList.size());
                // Query data
                List<Record> resultList = Db.find("SELECT * FROM TOMCAT_TEST");
                for (Record result : resultList) {
                    System.out.println(result.getStr("USERNAME"));
                }
                // Modify data
                for (int i = 0; i < 10; i++) {
                    Db.update("UPDATE TOMCAT_TEST SET USERNAME = 'Connection pool test" + i + "' WHERE ID = " + i);
                }
                // Query the modified data
                List<Record> modifiedList = Db.find("SELECT * FROM TOMCAT_TEST");
                System.out.println("-----After modification-----");
                for (Record modified : modifiedList) {
                    System.out.println(modified.getStr("USERNAME"));
                }
                renderJson("Data retrieved successfully");
            } catch (Exception e) {
                e.printStackTrace();
                renderJson("Error occurred");
            }
        }
    }
    
    package com.oceanbase.testtomcat.pojo;
    
    import com.jfinal.plugin.activerecord.Model;
    
    
        public class User extends Model<User> {
            public static final User dao = new User();
    
    }
    

    References

    For more information about OceanBase Connector/J, see OceanBase JDBC Driver.

    Previous topic

    Database connection pool configuration
    Last

    Next topic

    c3p0
    Next
    What is on this page
    Prerequisites
    Procedure
    Step 1: Import the tomcat-mysql-client project into IntelliJ IDEA
    Step 2: Obtain the connection information of OceanBase Database
    Step 3: Modify the database connection information in the tomcat-mysql-client project
    Step 4: Set up the Tomcat runtime environment of the tomcat-mysql-client project
    Step 5: Run the tomcat-mysql-client project
    Project code introduction
    Code in the pom.xml file
    application.properties
    Code in the web.xml file
    Introduction to the UserConfig.java file
    UserController.java
    Introduction to the User.java file
    Full code
    References