Database password dynamic sensing method, database password switching method and database password dynamic sensing system
Through the customized Hikari connection pool data source manager, the database password is sensed and switched in real time, solving the business interruption problem of the application when the database password is changed, ensuring the stable operation of the system.
Patent Information
- Application Number
- CN202510547670.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-28
- Publication Date
- 2025-07-22
AI Technical Summary
In the prior art, applications cannot perceive database password changes in real time, resulting in business interruptions and lack of automated password updates and switching mechanisms.
Using a custom Hikari connection pool-based data source manager, it interacts with the database interface to obtain database password changes in real time, and dynamically senses and switches database connection passwords without shutting down.
It realizes that applications can sense and switch connections in real time without shutdown after the database password changes, ensuring business continuity and improving system security and availability.
Smart Images

Figure CN120354403A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases, and particularly to a method for dynamically perceiving database passwords, a method for dynamically switching database passwords, a system for dynamically perceiving database passwords, a computer device, a computer-readable storage medium, and a computer program product. Background Art
[0002] The statements in this section merely provide background art related to the present invention and do not necessarily constitute prior art.
[0003] In the case where system security is becoming increasingly important, as the infrastructure for enterprise informatization construction, the security requirements for databases will also become more and more stringent. Therefore, many enterprises require the database itself to provide a mechanism for regularly updating passwords during enterprise informatization construction, and this requirement is particularly prominent within the financial industry. In order to ensure the continuous operation of the business system itself, it is required that the business application system must adapt to this dynamic password update mechanism of the database, so that the application system can dynamically perceive and successfully update and switch passwords after the database password is changed.
[0004] However, the current password perception and switching solutions have the following problems: (1) Application programs usually read database connection information, including usernames and passwords, from configuration files. If the update of the configuration file lags behind the change of the database password, the application program will not be able to obtain the latest password; (2) There is no dedicated tool or script to automate the password update and switching process. Without a real-time perception mechanism, the application program cannot actively obtain the change information of the database password. Summary of the Invention
[0005] To solve the deficiencies of the prior art, the present invention provides a method, a switching method, and a system for dynamically perceiving database passwords, which can ensure that the application program at the application layer can, without downtime, real-time perceive the new database password, establish a new database connection and continue to use it, thus ensuring the business continuity of the application program.
[0006] To achieve the above object, the present invention adopts the following technical solutions: In a first aspect, the present invention provides a method for dynamically perceiving database passwords.
[0007] A method for dynamically perceiving database passwords, applied to a data source manager based on a Hikari connection pool, includes the following processes: Obtain the latest database password; Attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the application's configuration file to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password in the configuration of the data source manager. Attempt to connect to the database using the latest database password. If the connection still fails, it is determined that the connection has failed. If the connection can be established normally, save the latest database password for the application's configuration file to call.
[0008] As a further limitation of the first aspect of the present invention, if the current database password is the same as the latest database password, attempt to connect again using the current database password. If the connection still fails, it is determined that the connection has failed.
[0009] As a further limitation of the first aspect of the present invention, the data source manager perceives the change of the database password in real time through the interface provided by the database for obtaining the database password to obtain the latest database password.
[0010] In a second aspect, the present invention provides a database password dynamic perception system.
[0011] A database password dynamic perception system applied to a data source manager based on the Hikari connection pool, comprising: A password acquisition unit configured to acquire the latest database password; A first connection attempt unit configured to attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the application's configuration file to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password in the configuration of the data source manager. A second connection attempt unit configured to attempt to connect to the database using the latest database password. If the connection still fails, it is determined that the connection has failed. If the connection can be established normally, save the latest database password for the application's configuration file to call.
[0012] In a third aspect, the present invention provides a database password dynamic switching method.
[0013] A database password dynamic switching method includes the following process: a data source manager based on the Hikari connection pool is configured in the application's configuration file, and the data source manager uses the method described in the first aspect of the present invention for database password dynamic perception; The application loads the data source manager according to the configuration file to obtain the current connection password of the database to connect to the database.
[0014] As a further limitation of the third aspect of the present invention, the data source manager defined as CAFHikariDataSource is configured into the configuration file Application.yaml, and the application loads CAFHikariDataSource according to the configuration file Application.yaml to obtain the current connection password of the database.
[0015] As a further limitation of the third aspect of the present invention, the Application.yaml configuration file is a configuration file based on the Spring Boot framework.
[0016] In a fourth aspect, the present invention provides a computer device, including: a processor and a computer-readable storage medium; The processor is adapted to execute a computer program; The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, it implements the database password dynamic perception method as described in the first aspect of the present invention.
[0017] In a fifth aspect, the present invention provides a computer-readable storage medium, which stores a computer program, and the computer program is adapted to be loaded and executed by a processor to implement the database password dynamic perception method as described in the first aspect of the present invention.
[0018] In a sixth aspect, the present invention provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the database password dynamic perception method as described in the first aspect of the present invention.
[0019] Compared with the prior art, the beneficial effects of the present invention are: 1. The present invention innovatively designs a custom data source manager based on the Hikari connection pool, and proposes a database password dynamic perception method. The data source manager attempts to connect to the database using the current database password. If the connection fails, it determines whether the current database password is the same as the latest database password. If they are not the same, the latest database password is set into the configuration of the data source manager. Through the interaction with the database interface in the custom data source manager, the change of the database-side password can be obtained in real time, which can ensure that the application program at the application layer can perceive the new database password in real time without downtime after the database password changes, establish a new database connection and continue to use, ensuring the business continuity of the application program.
[0020] 2. Based on the Hikari connection pool and the Spring Boot framework, the present invention combines a custom data source manager. After the application layer's application dynamically senses the update of the database password, the application layer dynamically switches the connection password, constructing a mechanism for real-time sensing and real-time switching. Under the framework of Spring Boot, the specific data source manager is described through a configuration file. Through the custom-designed data source manager, a data source for connection acquisition is provided to the Hikari connection pool, realizing the real-time sensing and real-time switching of the database password.
[0021] Advantages of additional aspects of the present invention will be partly given in the following description, partly will become apparent from the following description, or will be learned through the practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings forming a part of this specification are used to provide a further understanding of the present invention. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation to the present invention.
[0023] Figure 1 It is a schematic flowchart of the method for dynamically sensing the database password provided in Embodiment 1 of the present invention; Figure 2 It is a schematic flowchart of the method for dynamically switching the database password provided in Embodiment 2 of the present invention; Figure 3 It is a schematic diagram of a system for dynamically sensing the database password provided in Embodiment 3 of the present invention; Figure 4 It is a schematic diagram of a computer device provided in Embodiment 4 of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0024] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0025] It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which the present invention belongs.
[0026] Without conflict, the embodiments in the present invention and the features in the embodiments can be combined with each other.
[0027] Embodiment 1: As described in the background art, the traditional configuration method is unable to cope with the need for dynamic update of the database password. Once the database password changes, developers often need to manually modify the configuration file and restart the application service to make the changes take effect. This not only involves cumbersome operations but may also lead to business losses due to service interruptions. Currently, there is no dedicated tool or script to automate the password update and switching process. Without a real-time perception mechanism, the application cannot actively obtain the change information of the database password. In view of the problems existing in the existing methods, in this implementation method under the Spring Boot framework, the specific data source DataSource is described through a configuration file. By designing a custom DataSource data source, a data source for connection acquisition is provided to the Hikari connection pool. Through the interaction with the API interface of the database in the custom DataSource data source, the change of the database-side password can be obtained in real time. In this way, it can be ensured that after the database password changes, the application layer can perceive the password in real time without downtime, establish a new database connection and continue to use it, ensuring the business continuity of the application system.
[0028] Spring Boot used in this implementation method is an important member of the Spring family. Based on the Spring framework, through a series of default configurations and automatic assembly mechanisms, it greatly simplifies the initial setup and development process of Spring applications. In a Spring Boot application, the configuration of the data source (DataSource) is one of the key links, which determines how the application interacts with the database. Developers can define the specific parameters of the data source, such as the database URL, username, and password, through configuration files such as application.properties or application.yml.
[0029] The Hikari connection pool used in this implementation is a high-performance JDBC connection pool library. When the application starts, HikariCP initializes the connection pool according to the configuration parameters, creates the minimum number of idle connections, and is ready to respond to database connection requests at any time. When the application needs a database connection, it requests a connection from HikariCP. HikariCP checks whether there are available idle connections in the connection pool. If there are idle connections, it immediately returns them to the application. If there are no idle connections and the current number of connections has not reached the maximum number of connections, HikariCP creates a new connection and returns it to the application. If the current number of connections has reached the maximum number of connections and there are no available idle connections, the application needs to wait until there are available idle connections or a timeout occurs. When the application finishes the database operation, it needs to return the connection to the connection pool. HikariCP puts the connection back into the connection pool so that other requests can reuse it. HikariCP automatically maintains the health status of the connection pool, including detecting invalid connections, closing idle timeout connections, handling connection leaks, etc. HikariCP also provides a variety of monitoring metrics to help developers understand the performance and status of the connection pool.
[0030] More specifically, in this implementation, an innovative custom-designed data source manager CAFHikariDataSource based on the Hikari connection pool is designed. Based on the custom-designed data source manager CAFHikariDataSource, a method for dynamically perceiving the database password is proposed, as Figure 1 shown, including the following processes: S1.1: Obtain the latest database password; S1.2: Try to connect to the database using the current database password. If the connection is successful, save the current database password for the application's configuration file to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password into the configuration of the data source manager. S1.3: Try to connect to the database using the latest database password. If it is still unable to connect, it is determined that the connection fails. If it can be normally connected, save the latest database password for the application's configuration file to call.
[0031] In this implementation, the custom design process of the data source manager CAFHikariDataSource based on the Hikari connection pool includes: writing the CAFHikariDataSource data source manager and overriding the getConnection method of its base class to complete the verification and update of password updates.
[0032] This implementation provides a code form. It should be noted that this code form is only for illustrative purposes and is only used to illustrate the basic design process of the CAFHikariDataSource data source manager in this implementation, including: @Override public Connection getConnection() throws SQLException { var password = this.sourcePass.getCurrentPass(); try{ super.getConnection(); }catch (Exception e){ if(password.equals(oldpass)==false){ config.setPassword(password); super.getConnection(); } } The specific working logic of the above code form is as follows: (1) @Override indicates that this method overrides the getConnection method in the base class (or interface); (2) Declare a method getConnection, whose return value is of type Connection (database connection object); (3) The throws SQLException in the method getConnection declaration indicates that this method may throw a SQLException exception; (4) Define a variable password, and use var to automatically infer its type (var is used to declare the variable password); (5) Call the getCurrentPass() method of the sourcePass object in the current class to obtain the current password and assign the result to the variable password; (6) Use a "try block" to attempt to execute the getConnection method of the base class (by calling super.getConnection()); (7) If any exception is thrown when calling the base class method, it will enter the "catch block" for handling; (8) In the "catch block" (which is part of the exception handling mechanism and is used to catch and handle exceptions that may occur during program execution), determine whether the current password `password` is not equal to the variable `oldpass` (the old password). (9) If the current password `password` and `oldpass` (the old password) are not equal, enter the "if block" to execute the subsequent logic. (10) Call the `setPassword` method of the `config` object (i.e., the method for setting the password) to set the new password `password` into the configuration object. (11) Call the `getConnection` method of the base class again to attempt to establish a database connection.
[0033] In Java, the `getConnection` method of the base class is usually related to database connection and is a method in the `DataSource` interface or its implementation classes (such as `BasicDataSource`, `HikariDataSource`, etc.) for obtaining a database connection.
[0034] Through the above dynamic perception method, in this implementation, through the interaction between the data source manager based on the Hikari connection pool and the database interface, the change of the database password can be obtained in real time, ensuring that the application program at the application layer can perceive the new database password in real time without downtime after the database password changes, establish a new database connection and continue to use, thus ensuring the business continuity of the application program.
[0035] It should be noted that the dynamic perception method of this implementation can be applied in multiple technical fields as long as there is a "scenario where the change of the database password needs to be dynamically perceived", mainly including the financial field, the Internet field, the communication field, and the medical field, etc.
[0036] For example, the stability and security requirements of the banking system in the financial field are extremely high. The core business systems of banks, online payment platforms, etc. need to process a large amount of financial transaction data. Any business interruption may lead to serious economic losses and reputation risks. Through the dynamic data source management technology, financial institutions can seamlessly switch to a new connection when the database password changes, ensuring the continuity of transactions and the security of data. For example, the online banking system of a large bank adopts the Spring Boot framework and introduces the dynamic perception method of this implementation. During the regular change of the database password, the system can automatically perceive the password change and update the connection pool without downtime maintenance, effectively ensuring that users can perform operations such as transferring money and querying at any time.
[0037] For another example, Internet companies usually face challenges of high concurrency and large amounts of data, and at the same time need to iterate quickly and update frequently. The dynamic perception method of this implementation can help Internet companies better cope with these challenges. For example, during a promotional event on an e-commerce platform, the database access volume will increase sharply. At the same time, to ensure the security of the system, the database password may need to be adjusted dynamically. Through the dynamic perception method of this implementation, the e-commerce platform can update the database connection information in real time without interrupting the business, ensuring the stable operation of the system.
[0038] Embodiment 2: Based on the dynamic perception method proposed in the above Embodiment 1 and the custom CAFHikariDataSource data source manager, this implementation proposes a method for dynamically switching database passwords, as Figure 2 shown, including the following processes: S2.1: The data source manager based on the Hikari connection pool is configured in the application configuration file, and the data source manager uses the method described in Embodiment 1 of the present invention to perform dynamic perception of the database password; S2.2: The application loads the data source manager according to the configuration file to obtain the current connection password of the database for connecting to the database.
[0039] In this implementation, more specifically, the CAFHikariDataSource data source manager configured in the application.yaml configuration file implements the getConnection method of the JDK's DataSource interface. Through this method, the application layer can implement the way to obtain the database connection according to its own business needs.
[0040] In this implementation, based on the Application.yaml configuration file of Spring Boot, the CAFHikariDataSource data source manager can be configured in the system. By replacing the default DataSource of Spring Boot with the custom CAFHikariDataSource data source manager, the custom CAFHikariDataSource data source manager can take effect and be used in the system. In addition, the configuration file method can more conveniently and flexibly meet other subsequent expansion requirements.
[0041] The custom CAFHikariDataSource data source manager in this implementation method can internally and in real time sense the change of the database layer password through the API interface for obtaining the password provided by the database party. Once the database password changes, the CAFHikariDataSource data source manager will internally create a database connection based on the new password and update the database connection password information of this application.
[0042] More specifically, in this implementation method, adjust the following configuration in application.yaml to replace the default data source manager of Spring with a custom data source manager. It should be noted that the code form here is only for illustrative purposes and is only used to illustrate the configuration process of this implementation method, including: spring: mvc: servlet: load-on-startup: 0 datasource: type: io.iec.edp.caf.HikariDataSource The specific definition of the above code is as follows: spring: This is the top-level key for Spring configuration, indicating that the following configurations are all about the Spring framework; mvc: This indicates that the following configurations are about Spring MVC, which is a framework for building web applications; servlet: This indicates that the following configurations are about Servlets. In Spring MVC, Servlets are the core components for handling HTTP requests; load-on-startup:0: This is a configuration related to Servlet initialization. The load-on-startup attribute is used to specify the loading order of the Servlet. A value of 0 means that the Servlet container will load and initialize this Servlet immediately when starting up; datasource: This is the configuration related to the data source. The data source is the factory for database connections and is used to provide access to the database; type:io.iec.edp.caf.HikariDataSource: This is the key configuration here. It specifies which type of data source Spring should use. Here it is set to io.iec.edp.caf.HikariDataSource, which is a custom data source class.
[0043] Through the setting of the above dynamic perception and dynamic switching mechanisms, this implementation method is based on the Hikari connection pool and Spring Boot. By constructing a custom CAFHikariDataSource data source manager, it realizes the dynamic perception of database password updates at the application layer, and at the same time realizes the dynamic switching of connection passwords at the application layer, ensuring the business continuity of the application program, improving the security and availability of the system, and reducing the complexity of operation and maintenance.
[0044] Example 3: This implementation method proposes a dynamic database password perception system, as Figure 3 shown, applied to a data source manager based on the Hikari connection pool, including: A password acquisition unit, configured to: acquire the latest database password; A first connection attempt unit, configured to: attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the configuration file of the application program to call. If the connection fails, determine whether the current database password is the same as the latest database password. If not, set the latest database password to the configuration of the data source manager; A second connection attempt unit, configured to: attempt to connect to the database using the latest database password. If the connection still fails, it is determined that the connection fails; if the connection can be established normally, save the latest database password for the configuration file of the application program to call.
[0045] The dynamic database password perception system of this implementation method can be deployed on the server side. The server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, web servers, cloud communications, middleware services, domain name services, security services CDN, and big data and artificial intelligence platforms.
[0046] It can be understood that the above-mentioned various units can be separately or all merged into one or several other units to form, or some of them can be further split into multiple smaller units with more functions to form, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of this application. The above units are divided based on logical functions. In actual applications, the function of one unit can also be realized by multiple units, or the functions of multiple units can be realized by one unit. In other embodiments of this application, the system can also include other units. In actual applications, these functions can also be assisted by other units and can be realized by the cooperation of multiple units.
[0047] According to another embodiment of the present application, the system described in this embodiment can be constructed, and the method of Embodiment 1 of the present application can be implemented by running a computer program (including program code) that can execute the steps involved in the corresponding method described in Embodiment 1 on a general computing device such as a computer including processing elements and storage elements such as a Central Processing Unit (CPU), a Random Access Memory (RAM), and a Read-Only Memory (ROM). The computer program can be recorded on, for example, a computer-readable recording medium, loaded into the above computing device through the computer-readable recording medium, and run therein.
[0048] Embodiment 4: Based on the dynamic perception method proposed in Embodiment 1 and the custom CAFHikariDataSource data source manager, this implementation also proposes an electronic device, such as Figure 4 As shown, the electronic device includes a processor 1001, a communication interface 1002, and a computer-readable storage medium 1003. Among them, the processor 1001, the communication interface 1002, and the computer-readable storage medium 1003 can be connected through a bus or other means.
[0049] Among them, the communication interface 1002 is used to receive and send data. The computer-readable storage medium 1003 can be stored in the memory of the electronic device. The computer-readable storage medium 1003 is used to store a computer program. The computer program includes program instructions. The processor 1001 is used to execute the program instructions stored in the computer-readable storage medium 1003.
[0050] The processor 1001 (or CPU (Central Processing Unit, central processor)) is the computing core and control core of the electronic device, and is adapted to implement one or more instructions, specifically adapted to load and execute one or more instructions to implement the corresponding method flow or corresponding function.
[0051] The processor 1001 is configured to execute the following process: Obtain the latest database password; attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the application's configuration file to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password in the configuration of the data source manager; attempt to connect to the database using the latest database password. If the connection still fails, it is determined that the connection has failed; if the connection can be established normally, save the latest database password for the application's configuration file to call. For the detailed process, see the process in Embodiment 1 and it will not be elaborated here.
[0052] Embodiment 5: Based on the dynamic perception method proposed in the above-mentioned Embodiment 1 and the custom CAFHikariDataSource data source manager, this implementation proposes a computer-readable storage medium (Memory). A computer-readable storage medium is a memory device in an electronic device for storing programs and data. It can be understood that the computer-readable storage medium here can include both the built-in storage medium in the electronic device and, of course, the extended storage medium supported by the electronic device. The computer-readable storage medium provides a storage space, and this storage space stores the processing system of the electronic device.
[0053] Moreover, one or more instructions suitable for being loaded and executed by a processor are also stored in this storage space. These instructions can be one or more computer programs (including program codes). It should be noted that the computer-readable storage medium here can be a high-speed RAM memory or a non-volatile memory, such as at least one disk memory; optionally, it can also be at least one computer-readable storage medium located far from the aforementioned processor.
[0054] In one embodiment, one or more instructions are stored in the computer-readable storage medium; the processor loads and executes one or more instructions stored in the computer-readable storage medium to implement the following process: Obtain the latest database password; attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the application's configuration file to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password in the configuration of the data source manager; attempt to connect to the database using the latest database password. If the connection still fails, it is determined that the connection has failed; if the connection can be established normally, save the latest database password for the application's configuration file to call. For the detailed process, see the process in Embodiment 1 and it will not be elaborated here.
[0055] Embodiment 6: Based on the dynamic perception method proposed in the above-mentioned Embodiment 1 and the custom CAFHikariDataSource data source manager, this implementation provides a computer program product or a computer program. The computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium. A processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device performs the following processes: Obtain the latest database password; attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the configuration file of the application to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password to the configuration of the data source manager; attempt to connect to the database using the latest database password. If the connection still cannot be established, it is determined that the connection fails; if the connection can be established normally, save the latest database password for the configuration file of the application to call. For the detailed process, see the process of Embodiment 1, which will not be elaborated here.
[0056] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Skilled professionals can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of this application.
[0057] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted through a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired manner (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or a wireless manner (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data processing device such as a server or a data center that includes one or more integrated available media. The available medium can be a magnetic medium (such as a floppy disk, a hard disk, a magnetic tape), an optical medium (such as a DVD), or a semiconductor medium (such as a solid state disk (SSD)), etc.
[0058] The foregoing is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for dynamically perceiving database passwords, characterized in that Applied to the data source manager based on the Hikari connection pool, including the following procedures: Obtain the latest database password; Attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the application's configuration file to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password to the configuration of the data source manager; Attempt to connect to the database using the latest database password. If it is still unable to connect, it is determined that the connection fails; if it can be connected normally, save the latest database password for the application's configuration file to call.
2. The database password dynamic perception method according to claim 1, characterized in that If the current database password is the same as the latest database password, execute the connection again using the current database password. If it is still unable to connect, it is determined that the connection fails.
3. The database password dynamic perception method according to claim 1, characterized in that The data source manager perceives the change of the database password in real time through the interface provided by the database to obtain the latest database password.
4. A database password dynamic perception system, characterized in that, Applied to the data source manager based on the Hikari connection pool, including: A password acquisition unit configured to: obtain the latest database password; A first connection attempt unit configured to: attempt to connect to the database using the current database password. If the connection is successful, save the current database password for the application's configuration file to call. If the connection fails, determine whether the current database password is the same as the latest database password. If they are not the same, set the latest database password to the configuration of the data source manager; A second connection attempt unit configured to: attempt to connect to the database using the latest database password. If it is still unable to connect, it is determined that the connection fails; if it can be connected normally, save the latest database password for the application's configuration file to call.
5. A database password dynamic switching method, characterized in that The data source manager based on the Hikari connection pool is configured into the application's configuration file, and the data source manager uses the method described in any one of claims 1-3 to perform dynamic perception of the database password; The application loads the data source manager according to the configuration file to obtain the current connection password of the database to connect to the database.
6. The database password dynamic switching method according to claim 5, characterized in that The data source manager defined as CAFHikariDataSource is configured into the configuration file Application.yaml, and the application loads CAFHikariDataSource according to the configuration file Application.yaml to obtain the current connection password of the database.
7. The database password dynamic switching method according to claim 6, characterized in that The Application.yaml configuration file is a configuration file based on the Spring Boot framework.
8. A computer device, characterized in that, Comprising: A processor and a computer-readable storage medium; The processor is adapted to execute a computer program; The computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, it implements the database password dynamic perception method according to any one of claims 1 to 3.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, and the computer program is adapted to be loaded and executed by the processor to implement the database password dynamic perception method according to any one of claims 1 to 3.
10. A computer program product, characterized in that, The computer program product includes a computer program, and when the computer program is executed by the processor, it implements the database password dynamic perception method according to any one of claims 1 to 3.