Multi-type database metadata acquisition optimization method based on JDBC

By adopting optimization methods such as JDBC connection pool, precompiled SQL and cache mechanism in multi-type database metadata collection, the inefficiency problem caused by frequent switching of connections is solved, and database performance and acquisition efficiency are improved.

CN119322769APending Publication Date: 2025-01-17SHANGHAI INSPUR CLOUD COMPUTING SERVICE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411196551.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-29
Publication Date
2025-01-17

AI Technical Summary

Technical Problem

During the multi-type database metadata acquisition process, frequent switching and rebuilding of connections lead to inefficiency, affecting database performance.

Method used

Using JDBC-based method, by introducing connection pools, precompiling SQL statements, batch processing, cache mechanisms and database monitoring tools, the database connection and metadata collection process is optimized, including using PreparedStatement for parameterized queries, setting fetchSize and transaction boundaries, and establishing Common entity-class storage and monitor database performance for tuning.

Benefits of technology

It improves the efficiency of metadata collection of multi-type databases, reduces the number of database accesses and resource consumption, and improves database performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119322769A_ABST
    Figure CN119322769A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-type database metadata acquisition optimization method based on JDBC, and relates to the technical field of data acquisition. Comprising the following steps of: 1, introducing a required JDBC (Java Data Block Controller) in an application program to depend on a connection pool, establishing JDBC connection, configuring key parameters of the connection pool, applying for a database connection object through the connection pool, and directly acquiring the existing database connection object from the connection pool for connection access when a user or an application accesses the database; step 2, performing parameterized query by using an SQL (Structured Query Language) statement pre-compiled by PreparedState to obtain metadata information returned according to an actual demand; and 3, processing the returned metadata information, namely establishing a universal entity class for storing the metadata information aiming at various data source types, unifying formats of different types of database metadata information, storing, releasing resources, and releasing a database connection object back to a connection pool for next use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention discloses a JDBC-based multi-type database metadata collection optimization method, and relates to the technical field of data collection. Background Art

[0002] Metadata collection is widely used in many scenarios, such as data warehouse construction, business report analysis, data integration development, data aggregation and sharing, etc. At present, when collecting metadata information of various types of databases, it is necessary to frequently switch and rebuild connections, which makes the metadata collection of various types of databases inefficient and is not conducive to improving the performance of the database system. Summary of the invention

[0003] In view of the problems of the prior art, the present invention provides a JDBC-based multi-type database metadata collection optimization method, extracts metadata of multi-type databases based on JDBC, and improves performance by optimizing the extraction process.

[0004] The specific scheme proposed by the present invention is:

[0005] The present invention provides a JDBC-based multi-type database metadata collection optimization method, comprising:

[0006] Step 1: Introduce the required JDBC and connection pool dependencies in the application, establish a JDBC connection, configure the key parameters of the connection pool, apply for a database connection object through the connection pool, and directly obtain the existing database connection object from the connection pool for connection access when a user or application accesses the database;

[0007] Step 2: Use the SQL statement precompiled by PreparedStatement to perform parameterized query and obtain metadata information returned according to actual needs. The batch processing function of JDBC is used to combine multiple insert or update operations into a batch processing task for batch processing. By setting the fetchSize attribute of Statement, the size of the result set of metadata information obtained from the database is controlled. At the same time, the fetchSize and processing direction of ResultSet are set to improve the speed of large data processing. Set transaction boundaries to open transactions only when needed, and select the most appropriate transaction isolation level according to the needs of the application.

[0008] Step 3: Process the returned metadata information: For various data source types, establish a common entity class to store metadata information.

[0009] Unify the format and store metadata information of different types of databases.

[0010] Release resources and return the database connection object to the connection pool, waiting for the next use.

[0011] Furthermore, when establishing a JDBC connection in step 1 of the JDBC-based multi-type database metadata collection optimization method, the database driver class is loaded through the Class.forName() method. Once the driver is loaded, the connection with the database is established through the application using the DriverManager.getConnection() method.

[0012] Furthermore, in the JDBC-based multi-type database metadata collection optimization method, a cache mechanism is also established in step 2: for data that is frequently queried and has unchanged results, a cache mechanism is used to reduce the number of database accesses.

[0013] At the same time, a cache invalidation mechanism is set: when the metadata information of the database changes, the cached metadata information is invalidated, and during the invalidation process, the current cache is cleared when the metadata information changes.

[0014] Furthermore, in step 2 of the JDBC-based multi-type database metadata collection optimization method, a database monitoring tool is used to monitor the performance of the database, identify performance bottlenecks and perform tuning: adjust the JVM parameters according to the application requirements and hardware environment, and the JVM parameters include heap size and garbage collection algorithm.

[0015] The present invention also provides a JDBC-based multi-type database metadata collection and optimization device, including a connection management module, a data collection management module and a return processing module.

[0016] The connection management module introduces the required JDBC and connection pool dependencies into the application, establishes JDBC connections, configures key connection pool parameters, applies for database connection objects through the connection pool, and directly obtains existing database connection objects from the connection pool for connection access when a user or application accesses the database;

[0017] The data collection management module uses the SQL statement precompiled by PreparedStatement to perform parameterized queries and obtain metadata information returned according to actual needs. The data collection management module uses the batch processing function of JDBC to combine multiple insert or update operations into a batch processing task for batch processing; by setting the fetchSize attribute of Statement, the size of the result set of metadata information obtained from the database is controlled, and the fetchSize and processing direction of ResultSet are set to improve the speed of big data processing; transaction boundaries are set to open transactions only when needed, and the most appropriate transaction isolation level is selected according to the needs of the application;

[0018] The return processing module processes the returned metadata information: for various data source types, a common entity class is established to store metadata information.

[0019] Unify the format and store metadata information of different types of databases.

[0020] Release resources and return the database connection object to the connection pool, waiting for the next use.

[0021] Furthermore, when establishing a JDBC connection in the data collection management module of the JDBC-based multi-type database metadata collection and optimization device, the database driver class is loaded through the Class.forName() method. Once the driver is loaded, the connection with the database is established through the application using the DriverManager.getConnection() method.

[0022] Furthermore, the data collection management module of the JDBC-based multi-type database metadata collection optimization device also establishes a cache mechanism: for data that is frequently queried and has unchanged results, the cache mechanism is used to reduce the number of database accesses.

[0023] At the same time, the data collection management module sets a cache invalidation mechanism: when the metadata information of the database changes, the cached metadata information is invalidated, and the current cache is cleared during the invalidation process when the metadata information changes.

[0024] Furthermore, the data collection management module of the JDBC-based multi-type database metadata collection and optimization device also uses a database monitoring tool to monitor the performance of the database, identify performance bottlenecks and perform optimization: adjust the JVM parameters according to the application requirements and hardware environment, and the JVM parameters include heap size and garbage collection algorithm.

[0025] The benefits of the present invention are:

[0026] The present invention provides a JDBC-based multi-type database metadata collection optimization method, uses JDBC to establish a database connection and specifically optimizes the collection process, solves the problem of frequent switching of database connections affecting performance, and improves collection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] Figure 1 It is a schematic flow chart of the method of the present invention. DETAILED DESCRIPTION

[0028] JDBC (Java Database Connectivity) is a Java API that provides a standard interface for Java applications to interact with relational databases. JDBC allows developers to write database applications in pure Java without having to worry about the underlying implementation details of a specific database. Through JDBC, developers can execute SQL statements to query, insert, delete, and update the database and ensure that data transactions proceed normally. JDBC supports the ANSI SQL-92 standard, making it possible to call standard SQL commands from within a Java program. The main components of JDBC include: JDBC API and JDBC driver.

[0029] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.

[0030] Example 1

[0031] The method of the present invention presets the JDBC of the database type to be connected and optimizes the connection and acquisition process. The connected database may include multiple types, and the JDBC of various types of databases can be introduced for use during connection.

[0032] The present invention provides a JDBC-based multi-type database metadata collection optimization method, comprising:

[0033] Step 1: Introduce the required JDBC and connection pool dependencies in the application, establish a JDBC connection, configure the key parameters of the connection pool, apply for a database connection object through the connection pool, and directly obtain the existing database connection object from the connection pool for connection access when a user or application accesses the database.

[0034] When establishing a JDBC connection in step 1, the database driver class can be loaded through the Class.forName() method. Once the driver is loaded, the application uses the DriverManager.getConnection() method to establish a connection with the database.

[0035] Step 2: Use the SQL statement precompiled by PreparedStatement to perform parameterized queries and obtain metadata information returned according to actual needs. The batch processing function of JDBC is used to combine multiple insert or update operations into a batch processing task for batch processing; the size of the result set for obtaining metadata information from the database is controlled by setting the fetchSize property of the Statement, and the fetchSize and processing direction are set for the ResultSet to increase the speed of large data processing; transaction boundaries are set to open transactions only when needed, and the most appropriate transaction isolation level is selected according to the needs of the application. In addition to the aforementioned optimizations, a cache mechanism is also established in step 2: a cache mechanism is used to reduce the number of database accesses for data that is frequently queried and whose results remain unchanged.

[0036] At the same time, a cache invalidation mechanism is set: when the metadata information of the database changes, the cached metadata information is invalidated, and during the invalidation process, the current cache is cleared when the metadata information changes.

[0037] In step 2, a database monitoring tool is also used to monitor the performance of the database, identify performance bottlenecks and perform tuning: adjust the JVM parameters according to the application requirements and hardware environment. The JVM parameters include the heap size and garbage collection algorithm.

[0038] Step 3: Process the returned metadata information: For various data source types, establish a common entity class to store metadata information to avoid frequent creation of entities and increase resource consumption.

[0039] The metadata information of different types of databases is stored in a unified format to facilitate subsequent processing and front-end display.

[0040] Release resources and return the database connection object to the connection pool, waiting for the next use. For example, calling the close() method of the connection does not actually close the connection, but resets the connection object to a usable state. In addition, the ResultSet used when processing the result set is also closed to avoid wasting resources.

[0041] Example 2

[0042] The present invention also provides a JDBC-based multi-type database metadata collection and optimization device, including a connection management module, a data collection management module and a return processing module.

[0043] The connection management module introduces the required JDBC and connection pool dependencies into the application, establishes JDBC connections, configures key connection pool parameters, applies for database connection objects through the connection pool, and directly obtains existing database connection objects from the connection pool for connection access when a user or application accesses the database;

[0044] The data collection management module uses the SQL statement precompiled by PreparedStatement to perform parameterized queries and obtain metadata information returned according to actual needs. The data collection management module uses the batch processing function of JDBC to combine multiple insert or update operations into a batch processing task for batch processing; by setting the fetchSize attribute of Statement, the size of the result set of metadata information obtained from the database is controlled, and the fetchSize and processing direction of ResultSet are set to improve the speed of big data processing; transaction boundaries are set to open transactions only when needed, and the most appropriate transaction isolation level is selected according to the needs of the application;

[0045] The return processing module processes the returned metadata information: for various data source types, a common entity class is established to store metadata information.

[0046] Unify the format and store metadata information of different types of databases.

[0047] Release resources and return the database connection object to the connection pool, waiting for the next use.

[0048] As the information interaction and execution process between the modules in the above-mentioned device are based on the same concept as the embodiment of the method of the present invention, the specific contents can be found in the description of the embodiment of the method of the present invention and will not be repeated here.

[0049] Similarly, the device of the present invention uses JDBC to establish a database connection and specifically optimizes the collection process, thereby solving the problem of frequent switching of database connections affecting performance and improving collection efficiency.

[0050] It should be noted that not all steps and modules in the above-mentioned processes and device structures are necessary, and some steps or modules can be ignored according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.

[0051] The above-described embodiments are only preferred embodiments for fully illustrating the present invention, and the protection scope of the present invention is not limited thereto. Equivalent substitutions or changes made by those skilled in the art based on the present invention are within the protection scope of the present invention. The protection scope of the present invention shall be subject to the claims.

Claims

1. A JDBC-based multi-type database metadata collection optimization method, characterized by include: Step 1: Introduce the required JDBC and connection pool dependencies in the application, establish a JDBC connection, configure the key parameters of the connection pool, apply for a database connection object through the connection pool, and directly obtain the existing database connection object from the connection pool for connection access when a user or application accesses the database; Step 2: Use the SQL statement precompiled by PreparedStatement to perform parameterized query and obtain metadata information returned according to actual needs. The batch processing function of JDBC is used to combine multiple insert or update operations into a batch processing task for batch processing. By setting the fetchSize attribute of Statement, the size of the result set of metadata information obtained from the database is controlled. At the same time, the fetchSize and processing direction of ResultSet are set to improve the speed of large data processing. Set transaction boundaries to open transactions only when needed, and select the most appropriate transaction isolation level according to the needs of the application. Step 3: Process the returned metadata information: For various data source types, establish a common entity class to store metadata information. Unify the format and store metadata information of different types of databases. Release resources and return the database connection object to the connection pool, waiting for the next use.

2. According to the JDBC-based multi-type database metadata collection optimization method described in claim 1, it is characterized in that when establishing a JDBC connection in step 1, the database driver class is loaded through the Class.forName() method. Once the driver is loaded, the connection with the database is established through the application using the DriverManager.getConnection() method.

3. The JDBC-based multi-type database metadata collection optimization method according to claim 1 is characterized by: In step 2, a cache mechanism is also established: for data that is frequently queried and has unchanged results, a cache mechanism is used to reduce the number of database accesses. At the same time, a cache invalidation mechanism is set: when the metadata information of the database changes, the cached metadata information is invalidated, and during the invalidation process, the current cache is cleared when the metadata information changes.

4. The JDBC-based multi-type database metadata collection optimization method according to claim 1 is characterized by: In step 2, a database monitoring tool is also used to monitor the performance of the database, identify performance bottlenecks and perform tuning: adjust the JVM parameters according to the application requirements and hardware environment. The JVM parameters include the heap size and garbage collection algorithm.

5. A JDBC-based multi-type database metadata collection and optimization device, characterized by It includes connection management module, data acquisition management module and return processing module. The connection management module introduces the required JDBC and connection pool dependencies into the application, establishes JDBC connections, configures key connection pool parameters, applies for database connection objects through the connection pool, and directly obtains existing database connection objects from the connection pool for connection access when a user or application accesses the database; The data collection management module uses the SQL statement precompiled by PreparedStatement to perform parameterized queries and obtain metadata information returned according to actual needs. The data collection management module uses the batch processing function of JDBC to combine multiple insert or update operations into a batch processing task for batch processing; by setting the fetchSize attribute of Statement, the size of the result set of metadata information obtained from the database is controlled, and the fetchSize and processing direction of ResultSet are set to improve the speed of big data processing; transaction boundaries are set to open transactions only when needed, and the most appropriate transaction isolation level is selected according to the needs of the application; The return processing module processes the returned metadata information: for various data source types, a common entity class is established to store metadata information. Unify the format and store metadata information of different types of databases. Release resources and return the database connection object to the connection pool, waiting for the next use.

6. The JDBC-based multi-type database metadata collection and optimization device according to claim 5 is characterized in that the data When establishing a JDBC connection in the acquisition management module, the database driver class is loaded through the Class.forName() method. Once the driver is loaded, the application uses the DriverManager.getConnection() method to establish a connection with the database.

7. The JDBC-based multi-type database metadata collection and optimization device according to claim 5 is characterized in that the data The collection management module also establishes a cache mechanism: for data that is frequently queried and has unchanged results, a cache mechanism is used to reduce the number of database accesses. At the same time, the data collection management module sets a cache invalidation mechanism: when the metadata information of the database changes, the cached metadata information is invalidated, and the current cache is cleared during the invalidation process when the metadata information changes.

8. The JDBC-based multi-type database metadata collection and optimization device according to claim 5 is characterized by: The data collection management module also uses database monitoring tools to monitor database performance, identify performance bottlenecks and perform optimizations: adjust JVM parameters according to application requirements and hardware environment. JVM parameters include heap size and garbage collection algorithm.