Compatible method and device of multi-version database driver, medium and equipment
By renaming the class name of multi-version database drivers in the Maven project, the compatibility problem between multi-version database drivers is solved, and efficient data export and database compatibility improvement during the database system migration process is achieved.
Patent Information
- Application Number
- CN202411960479.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-06-27
AI Technical Summary
The prior art has complexity and inefficiency in compatibility between multi-version database drivers, resulting in the migration process being time-consuming and unable to fully retain the functionality and features of the original database.
Generate JAR packages for specific database versions by creating a standalone Maven project that contains different versions of JDBC drivers and their configuration files, and rename each version of JDBC driver class name using the maven-shade-plugin plugin.
It effectively avoids class name conflicts, ensures that the system can load and use multiple versions of drivers at the same time, improves the flexibility and efficiency of data export during database system migration, and enhances database compatibility.
Smart Images

Figure CN120216018A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and in particular, to a compatibility method, device, medium, and equipment for multi-version database drivers. Background Art
[0002] With the continuous development of database technology, in order to meet the ever-changing business needs, enterprises may need to upgrade or migrate database systems. For example, migrating from a database with lower performance to a database with higher performance, or migrating from a commercial database to an open-source database to reduce costs. In these processes, ensuring that the old version of the application can continue to run on the new database is crucial, otherwise it may lead to serious consequences such as business interruption or data loss. Therefore, solving the compatibility between multi-version database drivers has become the key to meeting the changing business needs.
[0003] In terms of the compatibility between multi-version database drivers, the existing technology mainly uses database migration tools to migrate the data and structure in one database system to another database system. For example, when migrating from MySQL to Oracle, MySQL Workbench or Oracle's Data Pump utility can be used to convert the data into the corresponding Oracle format.
[0004] Although the migration tool can reduce the risks brought by compatibility issues, the migration process may be complex and time-consuming, and may not be able to fully retain all the functions and features of the original database. Summary of the Invention
[0005] In view of this, the present invention provides a compatibility method, device, medium, and equipment for multi-version database drivers, which can improve the flexibility and efficiency of the data export process during the database system migration process.
[0006] In a first aspect, an embodiment of the present invention provides a compatibility method for multi-version database drivers, the method comprising:
[0007] Create an independent Maven project, and each branch of the Maven project contains different versions of JDBC drivers and their related configuration files;
[0008] Use the maven-shade-plugin plugin of the Maven project to rename the class names of each version of the JDBC driver, wherein the class names of each version of the JDBC driver are unique;
[0009] Configure the new driver class names in the META-INF / services / java.sql.Driver file of the Maven project;
[0010] Generate a JAR package for a specific database version using the described Maven project building tool. The JAR package should at least contain the JDBC driver with renamed class names and the updated META-INF / services / java.sql.Driver file.
[0011] Furthermore, create an independent Maven project. Each branch of the Maven project contains different versions of the JDBC driver and its related configuration files, including:
[0012] Use the archetype command of the Maven project or the Maven project template in the IDE to create an independent Maven project;
[0013] In the pom.xml file of the Maven project, in different branches, add <dependency>Element;
[0014] In different branches, create relevant configuration files for the JDBC driver of each version under the src / main / resources directory.
[0015] Furthermore, use the maven-shade-plugin of the Maven project to rename the class names of the JDBC driver for each branch version, where the class names of the JDBC driver for each version are uniquely included:
[0016] Add the maven-shade-plugin;
[0017] Use the maven-shade-plugin to rename the class names of the JDBC driver for each version, where the class names of the JDBC driver for each version are unique.
[0018] Furthermore, in the <build>In the part, add <plugins>Element, and add the configuration of the maven-shade-plugin to it to complete the addition of the maven-shade-plugin.
[0019] Furthermore, use the maven-shade-plugin to rename the class names of the JDBC drivers for each version, where the class names of the JDBC drivers for each version uniquely include:
[0020] In the maven-shade-plugin <configuration>In the part, use <relocations>Elements are used to define the renaming rules for each JDBC driver class and specify a unique package name prefix for each version of the JDBC driver.
[0021] Furthermore, configuring the new driver class name in the META-INF / services / java.sql.Driver file of the Maven project includes:
[0022] Under the src / main / resources / META-INF / services / directory, check whether there is a java.sql.Driver file;
[0023] When there is a java.sql.Driver file, in the java.sql.Driver file, add a line for each renamed JDBC driver class to specify its fully qualified class name.
[0024] Furthermore, using the Maven project build tool to generate a JAR package for a specific database version includes:
[0025] Check whether the configurations in the pom.xml file are correct, including all dependencies, plugins, and build settings;
[0026] When the configurations in the pom.xml file are correct, open a command line or terminal under the root directory of the Maven project and execute the mvn clean package command;
[0027] The Maven project builds the project according to the configurations in the pom.xml and generates a JAR package that includes all necessary dependencies, the renamed JDBC driver classes, and the updated META-INF / services / java.sql.Driver file.
[0028] In a second aspect, an embodiment of the present invention provides a compatibility device for multi-version database drivers, and the device includes:
[0029] A creation module, configured to create an independent Maven project, and each branch of the Maven project contains different versions of JDBC drivers and their related configuration files;
[0030] A renaming module, configured to use the maven-shade-plugin plugin of the Maven project to rename the class names of each version of the JDBC driver, and the class names of each version of the JDBC driver are unique;
[0031] A configuration module, configured to configure a new driver class name in the META-INF / services / java.sql.Driver file of the Maven project;
[0032] A JAR package generation module, configured to generate a JAR package for a specific database version by using the Maven project building tool, where the JAR package at least includes a JDBC driver with a renamed class name and an updated META-INF / services / java.sql.Driver file.
[0033] In a third aspect, an embodiment of the present invention provides a computer-readable storage medium, in which a computer program is stored, and the computer program is configured to execute the method according to any one of the first aspects when running.
[0034] In a fourth aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to run the computer program to execute the method according to any one of the first aspects.
[0035] In the technical solution provided by the embodiments of the present invention, on the one hand, by intelligently renaming the driver class, the problem of class name conflicts caused by the same class name in different versions of the JDBC driver is effectively avoided, ensuring that the system can load and use multiple versions of the driver simultaneously without naming conflicts, enabling the system to flexibly identify and load the corresponding version of the driver, thereby supporting seamless connection of multiple databases, greatly enhancing the database compatibility of the system, and meeting the enterprise's requirements for diverse database environments. At the same time, by intelligently renaming the driver class, this solution optimizes the database connection process and reduces connection delays and failures caused by class name conflicts. This helps improve the efficiency of data export. On the other hand, with the help of the Maven build tool, this solution realizes the automatic generation of the driver JAR package. Developers do not need to manually package and deploy the driver, thus simplifying the development process and improving the development efficiency. When a new database driver needs to be added, developers only need to add a new class name renaming rule according to the same configuration method without making large-scale modifications to the system. By configuring the relevant files of the maven-shade-plugin, developers can easily achieve tasks such as class name renaming and JAR package generation, reducing the workload of manual configuration. By intelligently matching and loading the corresponding version of the driver, potential errors caused by driver version mismatches are reduced, which helps ensure the stability and reliability of the system. On the third hand, since the driver class name is uniquely identified, when a connection problem occurs in the system, developers can more easily locate and diagnose the problem, thereby improving the maintainability of the system. On the fourth hand, since the system can support connections to multiple databases simultaneously, it is easier to implement parallel processing and export of data, further improving the efficiency of data processing. The design of this solution enables the system to easily support the upgrade of future versions of database drivers, only by updating the corresponding class name renaming rules and JAR packages. Brief Description of the Drawings
[0036] Figure 1 is a flowchart of a method for compatible multi-version database drivers provided in Embodiment 1 of the present invention;
[0037] Figure 2 is a schematic structural diagram of a device for compatible multi-version database drivers provided in Embodiment 2 of the present invention;
[0038] Figure 3 is a schematic structural diagram of an electronic device provided in Embodiment 3 of the present invention. Detailed Embodiments
[0039] To make the objectives, technical solutions and advantages of the present invention more clear, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0040] Embodiment 1
[0041] See Figure 1 , Figure 1 which is a flowchart of a compatibility method for a multi-version database driver provided by an embodiment of the present invention. The method includes the following steps:
[0042] Step 11, create an independent Maven project, and each branch of the Maven project contains different versions of the JDBC driver and its related configuration files.
[0043] This step is the basis of the entire process. First, an independent Maven project needs to be created, which will be used to manage and package different versions of the JDBC driver. In each branch of this project, multiple versions of the JDBC driver will be added as dependencies, and some additional configuration files (such as database connection configuration, log configuration, etc.) may be included.
[0044] Maven is a project management and build automation tool that is based on the concept of the Project Object Model (POM). Maven is a software project management tool that can help developers manage project builds, reports, and documentation. It uses a standard directory structure and a default build lifecycle, while allowing project creators to customize the project build process. Maven also provides a dependency management function that can automatically download and include the libraries required by the project.
[0045] JDBC (Java Database Connectivity) is the standard API for database connections in the Java programming language. It allows Java programs to interact with databases, execute SQL statements, and process results. The JDBC driver is an implementation of the JDBC API that provides the ability to communicate with a specific database.
[0046] Each database vendor will provide a JDBC driver corresponding to its database product. These drivers are usually distributed as JAR files and contain classes that implement the JDBC API. In a Java application, you need to add the corresponding JDBC driver JAR file to the project's classpath in order to be able to use the JDBC API to communicate with the database.
[0047] In each branch of a Maven project that contains different versions of the JDBC driver, the configuration files that may be included are as follows:
[0048] (1) pom.xml: This is the core configuration file of the Maven project, used to define the project's dependencies, plugins, build process, etc. In a Maven project that contains the JDBC driver, the pom.xml file will include dependency declarations for different versions of the JDBC driver.
[0049] (2) Database connection configuration file: This is usually a custom configuration file (such as database.properties or application.properties), used to store database connection information, such as the database URL, username, password, and driver class name. This information is read when the application runs and is used to establish a connection to the database.
[0050] (3) Log configuration file: Although not directly related to the JDBC driver, the log configuration file (such as logback.xml or log4j.properties) is very useful when debugging and monitoring database connections. They define the log level, format, and output location, helping developers understand the status and performance of the database connection.
[0051] (4) Other custom configuration files: Depending on the project requirements, you may also need other custom configuration files to store other information related to the JDBC connection, such as connection pool configuration, transaction management strategy, etc.
[0052] Step 12: Use the maven-shade-plugin plugin of the Maven project to rename the class names of the JDBC drivers for each branch version, where the class names of the JDBC drivers for each version are unique.
[0053] This step is the key to solving the class name conflict problem. Since different versions of the JDBC driver may contain classes with the same class name, directly packaging them together will cause class conflicts. By configuring the maven-shade-plugin plugin, unique class names can be generated for the JDBC drivers of each version, thus avoiding conflicts. This step is usually configured in the pom.xml file of Maven and executed as part of the build process.
[0054] Step 13: Configure the new driver class name in the META-INF / services / java.sql.Driver file of the Maven project.
[0055] Java's SPI (Service Provider Interface) mechanism allows service providers (in this case, JDBC drivers) to declare the services they provide. The META-INF / services / java.sql.Driver file is where JDBC drivers declare themselves as service providers for the java.sql.Driver service. After renaming the class names of the JDBC drivers, this file needs to be updated to include the new driver class names. In this way, when a Java application attempts to load a JDBC driver, it can find and load the correct class.
[0056] Step 14: Use the Maven project build tool to generate a JAR package for a specific database version. The JAR package should at least contain the JDBC driver with renamed class names and the updated META-INF / services / java.sql.Driver file.
[0057] This step is the end point of the entire process. After completing the previous steps, the Maven build tool (such as the mvn clean package command) can be used to generate a JAR package that contains all the necessary dependencies and configuration files. This JAR package will contain the renamed JDBC driver class, the updated META-INF / services / java.sql.Driver file, and any other necessary resources. The generated JAR package can be distributed to other developers or deployed to a production environment to support database connections for a specific version.
[0058] Next, the implementation methods of each step in the technical solution provided by the embodiments of the present invention will be elaborated in detail.
[0059] For step 11, a possible implementation method includes the following steps:
[0060] Step 111: Use the archetype command of the Maven project or the Maven project template in the IDE to create an independent Maven project.
[0061] Use the archetype command of Maven (such as mvn archetype:generate) or the Maven project template in the IDE (such as IntelliJ IDEA or Eclipse) to create a new Maven project.
[0062] The Archetype commands are mainly used in Maven projects. It allows users to create Maven projects from existing archetypes (prototypes or templates), or create archetypes from existing projects. These commands are executed through the Maven archetype plugin (maven-archetype-plugin).
[0063] Taking IntelliJ IDE as an example, IntelliJ IDEA provides some built-in Maven project templates. These templates cover common project types such as Java applications and web applications. When creating a new Maven project, users can select one of these built-in templates as a starting point and then customize it as needed. In addition to the built-in templates, IntelliJ IDEA also supports users to create and save custom Maven project templates. Users can configure the project structure, dependencies, plugins, etc. according to their project requirements and development habits, and then save them as templates for quickly creating similar projects in the future.
[0064] Step 112. In the pom.xml file of the Maven project, in different branches, add for each version of the JDBC driver <dependency>Element.
[0065] The pom.xml file of the created Maven project, in <dependencies>Add the dependencies of the JDBC driver for each version within the tag. The pom.xml file is the core configuration file of a Maven project, which contains key information such as the project's build information, dependency management, plugin configuration, etc. In the pom.xml file of a Maven project, <dependency>The element is used to specify the external libraries or frameworks that the project depends on. Each <dependency>The element usually contains the following subelements:
[0066] <groupid>: The group ID of the dependency, which uniquely identifies the group or project to which the dependency belongs.
[0067] <artifactid>: The unique identifier of a dependency within a group.
[0068] <version>: Version number of dependencies.
[0069] <scope>(Optional): The scope of the dependency, such as compile (dependency at compile time, default), test (dependency at test time), runtime (dependency at runtime), etc.
[0070] <classifier>(Optional): Used to distinguish different builds or packaging methods of the same version.
[0071] <type>(Optional): The type of the dependency, defaulting to jar.
[0072] <systempath>(Not recommended): If the dependency is not in the Maven Central Repository, you can specify a path in the local file system.
[0073] Step 113: In different branches, create relevant configuration files for the JDBC driver of each version in the src / main / resources directory.
[0074] Navigate to the src / main / resources directory of the Maven project and create a separate configuration file for the JDBC driver of each version. For example, you can create two files: jdbc-config-8.0.properties and jdbc-config-5.1.properties, and add the necessary JDBC connection information to these configuration files.
[0075] In a Maven project, the src / main / resources directory is an important directory for storing resource files required during project runtime. These resource files include, but are not limited to, configuration files (such as XML files, property files, etc.), internationalization resource files (such as message files in different languages), template files, static resources (such as pictures, audio, videos, etc.). The resource files in the src / main / resources directory will be copied to the target output directory (such as target / classes) during project build (such as packaging into a JAR or WAR file) so that they can be accessed by the application at runtime. When Maven builds the project, it will automatically copy the resource files under the src / main / resources directory to the target output directory. These resource files are usually packaged into the final JAR or WAR file to ensure their availability at runtime. The src / main / resources directory usually contains a large number of configuration files that define the behavior and parameters of the application. For example, database connection information, application parameters, log configuration, etc. Placing the configuration files in the src / main / resources directory makes it easy to switch between different environments (such as development, testing, production). By using Maven's Profiles feature, different configuration files can be defined for different environments and the appropriate configuration file can be selected during build.
[0076] In some embodiments of the present invention, Step 12 can be implemented through the following steps:
[0077] Step 121: In the <build>In the part, add <plugins>Element, and add the configuration of maven-shade-plugin to it to complete the addition of the maven-shade-plugin.
[0078] In a Maven project, the maven-shade-plugin is a powerful plugin that can repackage (shade) the JAR packages on which the project depends, including operations such as renaming classes, merging JARs, and optimizing JARs.
[0079] When adding the maven-shade-plugin, first, in the pom.xml file <build>Add in the part <plugins>Element and add the configuration of maven-shade-plugin in it. maven-shade-plugin is an official plugin of Maven, which provides the ability to repackage (shade) JAR files. <build>It is an element in the pom.xml file that contains the build configuration of the project. These configurations define how to compile the source code of the project, how to handle resource files, how to run tests, and how to use plugins, etc. <build>An element usually contains <plugins> 、 <sourcedirectory> 、 <testsourcedirectory> 、 <resources> 、 <testresources>and other sub-elements. <plugins>Yes <build>A child element of the element that is used to contain all the Maven plugin configurations for the build process.
[0080] In <plugins>Inside the element, multiple <plugin>element, each <plugin>The element defines the configuration of a Maven plug-in. Each <plugin>Elements all contain groupId, artifactId, and version attributes, which uniquely identify a plugin in the Maven repository. In addition, <plugin>The element may also contain <executions>Sub-elements, which are used to define the execution timing and targets of the plugin.
[0081] When adding the maven-shade-plugin, you can follow these steps:
[0082] Open the pom.xml file and find <build>Element, if <build>There is no in the element <plugins>If there is a sub-element, add one, at <plugins>Inside the child element, add a <plugin>element and set its groupId to org.apache.maven.plugins, artifactId to maven-shade-plugin, and a suitable version. In <plugin>Inside the element, add a <executions>Child element, used to define the execution configuration of the maven-shade-plugin, in <executions>Inside the child element, add a <execution>element and set its phase attribute to package (or the phase in which it wishes the plug-in to execute), and a <goals>Sub-elements, within <goals>Inside the child element, add a <goal>Element and set its value to shade, which is a goal of the maven-shade-plugin for performing the repackaging operation, (optional) at <execution>Inside the element, it is also possible to add a <configuration>Sub-elements, used to configure specific options of the maven-shade-plugin, such as class renaming rules, merging strategies, etc.
[0083] Step 122, use the maven-shade-plugin to rename the class names of the JDBC driver for each version, where the class names of the JDBC driver for each version are unique.
[0084] In this step, first, determine which classes of the JDBC driver need to be renamed. This usually includes the main class of the driver (such as the implementation of the Driver class) and any auxiliary classes that may conflict with other versions. In the pom.xml file, add a configuration for the maven-shade-plugin to specify the classes to be renamed and their new names. You can use <relocations>Elements are used to define the renaming rules for class names. However, since the class names of JDBC drivers are usually fixed and defined by the JDBC specification, it is necessary to specify a new unique package name or class name for each class in the driver. After renaming the classes of the JDBC driver, it is necessary to ensure that the application can correctly load and use these renamed classes. It may be necessary to modify the application's code to use the new class names. In addition, since JDBC drivers usually interact with database servers, renaming classes may disrupt communication with the database server. After making the above changes, it is necessary to thoroughly test the application to ensure that it can correctly interact with the renamed JDBC driver. This includes testing all database interaction functions such as database connection, query execution, result set processing, etc.
[0085] In some embodiments, step 14 can be implemented through the following steps:
[0086] Step 141: Check whether there is a java.sql.Driver file in the src / main / resources / META-INF / services / directory.
[0087] In this step, first navigate to the resource directory: Open the src / main / resources / META-INF / services / directory of the Maven project. Then, look for the java.sql.Driver file: Check whether there is a file named java.sql.Driver in this directory. This file is usually provided by the JDBC driver JAR package, but if you are building a custom JAR or WAR package that contains multiple JDBC drivers, you need to create or modify this file manually.
[0088] Step 142: When there is a java.sql.Driver file, add a line in the java.sql.Driver file to specify the fully qualified class name for each renamed JDBC driver class.
[0089] In this step, first, open the java.sql.Driver file using a text editor. After that, for each JDBC driver class renamed using the maven-shade-plugin, add a line in the file to specify its new fully qualified class name. Ensure that each class name occupies a separate line and there are no extra spaces or characters. If there are multiple renamed JDBC driver classes, a line needs to be added for each class.
[0090] In some embodiments, the implementation of generating a JAR package for a specific database version using the Maven project building tool in step 14 may include the following steps:
[0091] Step 141, check whether the configurations in the pom.xml file are correct, including all dependencies, plugins, and build settings.
[0092] In this step, first ensure that all necessary dependencies are listed in the pom.xml file, including JDBC driver dependencies and any other library or framework dependencies. After that, check whether the maven-shade-plugin or any other Maven plugin for tasks such as handling class name renaming and JAR package packaging is included. For the maven-shade-plugin, it is necessary to configure <relocations>Elements are used to specify which classes need to be renamed and their new names. After that, ensure that the <build>Partially configure various settings during the build process, such as the directory structure of source code and resource files, the name and version of the final JAR package, etc. Finally, check if there are any specific configurations related to the database version, such as database connection information (although this information is usually not directly placed in pom.xml but in a configuration file or environment variables).
[0093] Step 142: When the configuration in the pom.xml file is correct, open a command line or terminal in the root directory of the Maven project and execute the mvn clean package command.
[0094] In this step, first, open a command line or terminal, navigate to the root directory of the Maven project, execute the Maven command, enter mvn clean package and press Enter. This command will perform the following operations: clean phase: Clean all files generated by the previous build (such as the contents of the target directory). package phase: Compile the source code and resource files of the project, package them into a JAR or WAR file (depending on the type of your project), and place it in the target directory.
[0095] Step 143: The Maven project builds the project according to the configuration in the pom.xml and generates a JAR package that contains all necessary dependencies, the renamed JDBC driver class, and the updated META-INF / services / java.sql.Driver file.
[0096] In this step, Maven will execute the build process according to the configuration in pom.xml. This includes compiling the code, processing resource files, running any necessary tests, applying the class name renaming rules of the maven-shade-plugin, etc. Then, in the target directory, find a newly generated JAR package file. This file should contain all necessary dependencies (if Maven is configured to include these dependencies, for example, using the packaging options of the maven-assembly-plugin or maven-shade-plugin), the renamed JDBC driver class, and the updated META-INF / services / java.sql.Driver file (if you modified it according to the previous steps). Finally, you can use jar tf <jar-file>Use commands to view the contents of the JAR package, or use Java's ServiceLoader mechanism to test whether the JDBC driver is loaded correctly.
[0097] In the technical solution provided by the embodiment of the present invention, on the one hand, by intelligently renaming the driver class, the problem of class name conflicts caused by the same class name in different versions of the JDBC driver is effectively avoided, ensuring that the system can load and use multiple versions of the driver simultaneously without naming conflicts, enabling the system to flexibly identify and load the corresponding version of the driver, thus supporting seamless connection of multiple databases, greatly enhancing the database compatibility of the system, and meeting the enterprise's requirements for diverse database environments. At the same time, by intelligently renaming the driver class, this solution optimizes the database connection process and reduces connection delays and failures caused by class name conflicts. This helps improve the efficiency of data export. On the other hand, with the help of the Maven build tool, this solution realizes the automatic generation of the driver JAR package. Developers do not need to manually package and deploy the driver, thus simplifying the development process and improving the development efficiency. When a new database driver needs to be added, developers only need to add a new class name renaming rule according to the same configuration method without making large-scale modifications to the system. By configuring the relevant files of the maven-shade-plugin, developers can easily achieve tasks such as class name renaming and JAR package generation, reducing the workload of manual configuration. By intelligently matching and loading the corresponding version of the driver, potential errors caused by driver version mismatch are reduced, which helps ensure the stability and reliability of the system. On the third hand, since the driver class name is uniquely identified, when connection problems occur in the system, developers can more easily locate and diagnose the problem, thus improving the maintainability of the system. On the fourth hand, since the system can support connections to multiple databases simultaneously, it is easier to implement parallel processing and export of data, further improving the efficiency of data processing. The design of this solution enables the system to easily support the upgrade of future versions of the database driver, only by updating the corresponding class name renaming rule and JAR package.
[0098] Embodiment 2
[0099] See Figure 2 , Figure 2 is a schematic structural diagram of a compatible device for multi-version database drivers provided by the second embodiment of the present invention. The device includes:
[0100] A creation module 21, configured to create an independent Maven project, and each branch of the Maven project contains different versions of the JDBC driver and its related configuration files;
[0101] The rename module 22 is used to rename the class names of the JDBC drivers for each version using the maven-shade-plugin plugin of the Maven project, where the class names of the JDBC drivers for each version are unique;
[0102] The configuration module 23 is used to configure the new driver class name in the META-INF / services / java.sql.Driver file of the Maven project;
[0103] The JAR package generation module 24 is used to generate a JAR package for a specific database version using the Maven project build tool, and the JAR package at least includes the JDBC driver with renamed class names and the updated META-INF / services / java.sql.Driver file.
[0104] In some embodiments, the creation module 21 may include:
[0105] The first creation subunit 211 is used to create an independent Maven project using the archetype command of the Maven project or the Maven project template in the IDE;
[0106] The addition subunit 212 is used to add, in different branches, for each version of the JDBC driver in the pom.xml file of the Maven project <dependency>Element;
[0107] The second creation subunit 213 is used to create relevant configuration files for each version of the JDBC driver under the src / main / resources directory in different branches.
[0108] In some embodiments, the renaming module 22 may include:
[0109] The first addition unit 221 is used for the <build>In the part, add <plugins>Element, and add the configuration of the maven-shade-plugin to it to complete the addition of the maven-shade-plugin
[0110] Rename unit 222 is used to rename the class name of the JDBC driver for each version using the maven-shade-plugin, where the class name of the JDBC driver for each version is unique.
[0111] In some embodiments, the configuration module 23 may include:
[0112] The first checking unit 231 is used to check whether there is a java.sql.Driver file in the src / main / resources / META-INF / services / directory;
[0113] The second adding unit 232 is used to add a line specifying its fully qualified class name for each renamed JDBC driver class in the java.sql.Driver file when the java.sql.Driver file exists.
[0114] In some embodiments, the JAR package generation module 24 may include:
[0115] The second checking unit 241 is used to check whether the configuration in the pom.xml file is correct, including all dependencies, plugins, and build settings;
[0116] The execution unit 242 is used to open a command line or terminal in the root directory of the Maven project and execute the mvn clean package command when the configuration in the pom.xml file is correct;
[0117] The generation unit 243 is used to cause the Maven project to build the project according to the configuration in the pom.xml and generate a JAR package containing all necessary dependencies, renamed JDBC driver classes, and updated META-INF / services / java.sql.Driver file.
[0118] Thus, for the technical solution provided by the embodiments of the present invention, on the one hand, by intelligently renaming the driver classes, the problem of class name conflicts caused by the same class names in different versions of JDBC drivers is effectively avoided, ensuring that the system can load and use multiple versions of drivers simultaneously without naming conflicts, enabling the system to flexibly identify and load the corresponding version of the driver, thereby supporting seamless connection of multiple databases, greatly enhancing the database compatibility of the system, and meeting the enterprise's needs for diverse database environments. At the same time, by intelligently renaming the driver classes, this solution optimizes the database connection process and reduces connection delays and failures caused by class name conflicts. This helps improve the efficiency of data export. On the other hand, with the help of the Maven build tool, this solution realizes the automatic generation of driver JAR packages. Developers do not need to manually package and deploy the drivers, thus simplifying the development process and improving development efficiency. When a new database driver needs to be added, developers only need to add a new class name renaming rule in the same configuration manner without making large-scale modifications to the system. By configuring the relevant files of the maven-shade-plugin, developers can easily implement tasks such as class name renaming and JAR package generation, reducing the workload of manual configuration. By intelligently matching and loading the corresponding version of the driver, potential errors caused by driver version mismatches are reduced, which helps ensure the stability and reliability of the system. On the third hand, since the driver class names are uniquely identified, when connection problems occur in the system, developers can more easily locate and diagnose the problems, thereby improving the maintainability of the system. On the fourth hand, since the system can support connections of multiple databases simultaneously, data parallel processing and export can be more easily achieved, further improving the efficiency of data processing. The design of this solution enables the system to easily support the upgrade of future versions of database drivers, only by updating the corresponding class name renaming rules and JAR packages.
[0119] It should be noted that the multi-version database driver compatibility device in the embodiments of the present invention and the multi-version database driver compatibility method in the above embodiments belong to the same inventive concept. Technical details not described in detail in this device can be referred to the relevant descriptions of the method above and will not be repeated here.
[0120] In addition, the embodiments of the present invention further provide a computer-readable storage medium, in which a computer program is stored, and the computer program is configured to execute the method described above when running.
[0121] Figure 3 The schematic structural diagram of an electronic device 10 that can be used to implement the embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described herein and / or claimed.
[0122] As Figure 3 shown, the electronic device 10 includes at least one processor 11, and a memory communicatively connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc. The memory stores a computer program executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. The input / output (I / O) interface 15 is also connected to the bus 14.
[0123] Multiple components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a magnetic disk, an optical disc, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0124] The processor 11 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the idle detection method.
[0125] In some embodiments, the idle detection method may be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the idle detection method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to execute the idle detection method by any other suitable means (e.g., by means of firmware).
[0126] The various embodiments of the systems and techniques described above in this document may be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on a chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs executable and / or interpretable on a programmable system including at least one programmable processor, which may be a special-purpose or general-purpose programmable processor that receives data and instructions from a storage system, at least one input device, and at least one output device, and transmits the data and instructions to the storage system, the at least one input device, and the at least one output device.
[0127] The computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The computer programs may be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine, or entirely on the remote machine or server.
[0128] In the context of the present invention, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0129] To provide for interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can also be used to provide for interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0130] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0131] A computing system may include a client and a server. The client and the server are generally far from each other and usually interact via a communication network. The client-server relationship is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system, solving the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.
[0132] It should be understood that various forms of processes shown above can be used, with steps reordered, added or deleted. For example, the steps recited in the present invention can be executed in parallel, sequentially or in a different order, as long as the desired results of the technical solution of the present invention can be achieved, and no limitation is made herein.
[0133] The above specific embodiments do not constitute a limitation on the protection scope of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principle of the present invention shall be included within the protection scope of the present invention.< / plugins> < / build> < / dependency> < / build> < / relocations> < / relocations> < / configuration> < / execution> < / goal> < / goals> < / goals> < / execution> < / executions> < / executions> < / plugin> < / plugin> < / plugins> < / plugins> < / build> < / build> < / executions> < / plugin> < / plugin> < / plugin> < / plugin> < / plugins> < / build> < / plugins> < / testresources> < / resources> < / testsourcedirectory> < / sourcedirectory> < / plugins> < / build> < / build> < / plugins> < / build> < / plugins> < / build> < / systempath> < / type> < / classifier> < / scope> < / version> < / artifactid> < / groupid> < / dependency> < / dependency> < / dependencies> < / dependency> < / relocations> < / configuration> < / plugins> < / build> < / dependency>
Claims
1. A compatibility method for a multi-version database driver, characterized in that: The method comprises: Create an independent Maven project, each branch of which contains different versions of JDBC drivers and their related configuration files; Use the maven-shade-plugin of the Maven project to rename the class name of each version of the JDBC driver, wherein the class name of each version of the JDBC driver is unique; Configure the new driver class name in the META-INF / services / java.sql.Driver file of the Maven project; The Maven project building tool is used to generate a JAR package for a specific database version, wherein the JAR package at least includes a JDBC driver with a renamed class name and an updated META-INF / services / java.sql.Driver file.
2. The method according to claim 1, characterized in that Create an independent Maven project. Each branch in the Maven project contains different versions of JDBC drivers and their related configuration files, including: Use the Maven project archetype command or the Maven project template in the IDE to create an independent Maven project; In the pom.xml file of the said Maven project, in different branches, for each version of the JDBC driver add <dependency> element;< / dependency> In different branches, create relevant configuration files for each version of the JDBC driver in the src / main / resources directory.
3. The method according to claim 2, characterized in that Use the maven-shade-plugin of the Maven project to rename the class name of each branch version of the JDBC driver, where the class name of each version of the JDBC driver uniquely includes: Add the maven-shade-plugin plugin; The maven-shade-plugin is used to rename the class name of each version of the JDBC driver, wherein the class name of each version of the JDBC driver is unique.
4. The method according to claim 3, characterized in that In the pom.xml file <build>section, add <plugins> Element and add the configuration of maven-shade-plugin to it to complete adding the maven-shade-plugin plug-in.< / plugins> < / build> 5. The method according to claim 4, characterized in that Use the maven-shade-plugin to rename the class name of each version of the JDBC driver, where the class name of each version of the JDBC driver uniquely includes: In maven-shade-plugin <configuration>Part, use <relocations> Element to define the renaming rules for each JDBC driver class and specify a unique package name prefix for each version of the JDBC driver.< / relocations> < / configuration> 6. The method according to claim 5, characterized in that The configuration of the new driver class name in the META-INF / services / java.sql.Driver file of the Maven project includes: In the src / main / resources / META-INF / services / directory, check whether the java.sql.Driver file exists; If a java.sql.Driver file exists, add a line in the java.sql.Driver file for each renamed JDBC driver class, specifying its fully qualified class name.
7. The method according to claim 2, characterized in that: Using the Maven project build tool to generate a JAR package for a specific database version includes: Check whether the configuration in the pom.xml file is correct, including all dependencies, plugins, and build settings; When the configuration in the pom.xml file is correct, open a command line or terminal in the root directory of the Maven project and execute the mvn clean package command; The Maven project builds the project according to the configuration in the pom.xml and generates a JAR package containing all necessary dependencies, the renamed JDBC driver class and the updated META-INF / services / java.sql.Driver file.
8. A compatible device for a multi-version database driver, characterized in that: The device comprises: Create a module for creating an independent Maven project, each branch of which contains different versions of JDBC drivers and related configuration files; A renaming module, used to rename the class name of each version of the JDBC driver using the maven-shade-plugin plug-in of the Maven project, wherein the class name of each version of the JDBC driver is unique; A configuration module for configuring a new driver class name in the META-INF / services / java.sql.Driver file of the Maven project; The JAR package generation module is used to use the Maven project construction tool to generate a JAR package for a specific database version, wherein the JAR package at least includes a JDBC driver with a renamed class name and an updated META-INF / services / java.sql.Driver file.
9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 7.
Citation Information
Cited By
JDBC-based multi-database adaptation center construction method
CN121478750A