Methods, devices, electronic equipment and storage media for accessing differentiated databases
By utilizing a parsing and transformation interface to process query fields in the differentiated database access method, the complexity and high transformation cost of application access to differentiated databases are solved, achieving convenient and secure data access.
Patent Information
- Application Number
- CN202310797946.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-30
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2043-06-30
AI Technical Summary
Existing applications struggle to efficiently access differentiated databases, and the transformation costs are high and the adaptation process is complex.
By obtaining the application's access request, determining its type, and creating a corresponding second driver manager, the query fields are processed using a parsing and conversion interface to achieve connection and data access to the target database, avoiding direct access to the native driver manager.
It improves the ease of access and security of differentiated databases, while maintaining the data structure and interaction methods unchanged, thus enhancing compatibility.
Smart Images

Figure CN117131081B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of computer artificial intelligence and data security technology, and in particular to a method, apparatus, electronic device and storage medium for accessing differentiated databases. Background Technology
[0002] The goal of domestic substitution is to establish independent and controllable IT industry standards and ecosystems by reconstructing all aspects of IT hardware and software. As a result, differentiated databases have been formed, and their data structures and interaction methods differ from the original databases. This makes it difficult for existing applications to access these databases, resulting in problems such as high transformation costs and complex adaptation work. Summary of the Invention
[0003] The main objective of this invention is to provide a method, apparatus, electronic device, and storage medium for accessing a differentiated database, which improves access convenience and security without changing the data structure and interaction method of the differentiated database.
[0004] One aspect of the present invention provides a method for accessing a differentiated database, comprising:
[0005] Obtain the application's access request to the target database, determine the type of the accessed application and the first query field, wherein the application type is used to determine the first driver management for accessing the target database;
[0006] A second driver management is created based on the type of the driver manager and the type of the application, and the target database is connected through the second driver management.
[0007] The first query field is parsed and transformed by the second driver management to obtain the second query field. Based on the first driver management, the second driver management, and the second query field, an access is performed to the target database to obtain the query result.
[0008] The query results are obtained through the second driver management and returned to the application.
[0009] According to the differentiated database access method, the application type includes software programs developed based on one of the programming languages JAVA, C / C++, PHP and PYTHON, and the driver manager type includes one of JDBC and ODBC.
[0010] According to the differentiated database access method, creating a second driver management based on the driver manager type and the application type includes:
[0011] When the application type is JAVA, the second driver management is generated based on JDBC using a virtual interface.
[0012] When the application type is one of C / C++, PHP, and PYTHON, the second driver management is generated based on ODBC using an interception method.
[0013] According to the differentiated database access method, connecting to the target database through the first driver management and the second driver management includes:
[0014] When the application type is JAVA, the configuration file of the target database is obtained through the second driver management, the first driver management is loaded using the JAVA reflection mechanism and the configuration file, and a connection with the target database is established through the first driver management.
[0015] When the application is of type C / C++, PHP, or PYTHON, the configuration file of the target database is obtained through the second driver management, the first driver management is obtained and loaded according to the configuration file, and a connection with the target database is established according to the database operation interface in the first driver management.
[0016] According to the differentiated database access method, the first query field is parsed and transformed through a second driver management to obtain a second query field, and access is performed to the target database based on the first driver management, the second driver management, and the second query field, including:
[0017] The first query field is obtained through the second driver management, and the first query field is parsed and transformed using a parsing and transformation interface to obtain the second query field. The second query field is then used to perform a query through the first driver management and the target database to obtain the query result.
[0018] According to the differentiated database access method, the parsing and conversion interface is used to parse the first query field to obtain query information, and convert the first query field according to the syntax rules of the target database and the query information to obtain the second query field that conforms to the query rules of the target database.
[0019] The method for accessing the differentiated database also includes:
[0020] When the application is of type C / C++, PHP, or PYTHON, the parsing and conversion interface is loaded by the JNI virtual machine through the second driver management to complete the parsing and conversion of the first query field.
[0021] Another aspect of the present invention provides an access device for a differentiated database, comprising:
[0022] The access module is used to obtain the application's access request to the target database, determine the type of the accessed application and the first query field, wherein the application type is used to determine the first driver management for accessing the target database;
[0023] The connection module is used to create a second driver management based on the type of the driver manager and the type of the application, and connect to the target database through the second driver management;
[0024] The interception module is used to parse and transform the first query field through the second driver management to obtain the second query field, and to perform access to the target database according to the first driver management, the second driver management and the second query field to obtain the query result;
[0025] The return module is used to obtain the query results through the second driver management and return them to the application.
[0026] Another aspect of the present invention provides an electronic device, including a processor and a memory;
[0027] The memory is used to store programs;
[0028] The processor executes the program to implement the method as described above.
[0029] This invention also discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the methods described above.
[0030] The beneficial effects of this invention are as follows: For JDBC driver managers used by JAVA applications, and ODBC driver managers corresponding to C / C++, PHP, and PYTHON language applications, the invention loads the target database connection configuration information read by a second JDBC-based driver manager, then interacts with the database through the database's native JDBC driver. Furthermore, the second ODBC-based driver manager adds interception of access query fields, calls the statement parsing and conversion interface to convert the query fields, and completes data querying and return through the native driver manager. This eliminates the need to modify the native driver manager, avoids direct access to the target database by the application, improves the security of the target database, and enhances the compatibility of accessing and storing data in the target database.
[0031] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0032] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:
[0033] Figure 1 This is a schematic diagram of the access method for a differentiated database according to an embodiment of the present invention.
[0034] Figure 2 This is a schematic diagram of the connection process for the second driver management according to an embodiment of the present invention.
[0035] Figure 3 This is a schematic diagram of the data query process based on the second driver management of JDBC in an embodiment of the present invention.
[0036] Figure 4 This is a schematic diagram of the data query process based on the second driver management of JDBC in an embodiment of the present invention.
[0037] Figure 5 This is a diagram illustrating the overall architecture of a differentiated database access according to an embodiment of the present invention.
[0038] Figure 6 This is a schematic diagram of a differential database access device according to an embodiment of the present invention. Detailed Implementation
[0039] The embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings. Throughout the description, the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions. In the following description, suffixes such as "module," "part," or "unit" used to denote elements are used only for the purpose of illustrative purposes and have no specific meaning in themselves. Therefore, "module," "part," or "unit" can be used interchangeably. Terms such as "first," "second," etc., are used only to distinguish technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the sequential relationship of the indicated technical features. In the following description, the consecutive reference numerals for method steps are for ease of review and understanding. Adjusting the implementation order of steps, in conjunction with the overall technical solution of the present invention and the logical relationship between the various steps, will not affect the technical effect achieved by the technical solution of the present invention. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0040] refer to Figure 1 , Figure 1 A flowchart illustrating the access method for a differentiated database, including but not limited to steps S100~S400:
[0041] S100: Obtain the application's access request to the target database, determine the type of the accessed application and the first query field, whereby the application type is used to determine the first driver management for accessing the target database.
[0042] In some embodiments, the target database is a differentiated database, that is, it is not a common database such as SQL Server, Oracle, or MySQL, but a database with different data structures, such as Wuhan Dameng or Renmin University Kingbase.
[0043] It is understood that the first driver management includes JDBC and ODBC, where JDBC is the driver and ODBC is the driver manager. Unless otherwise specified, JDBC and ODBC in this embodiment are as described above.
[0044] In some embodiments, the first query field is a query request issued by the application, which may be an SQL statement, a query string, etc., wherein the SQL statement is not a query request that satisfies the differential database query syntax rules.
[0045] In some embodiments, the program types include JAVA, C / C++, PHP, PYTHON, etc., where JAVA language applications correspond to JDBC driver managers and interact with the database through JDBC driver managers (native drivers), while C / C++, PHP, and PYTHON interact with the database through ODBC driver managers (native drivers).
[0046] In some embodiments, when the application type is JAVA, a second driver is generated using a virtual interface based on JDBC; when the application type is one of C / C++, PHP, or PYTHON, a second driver is generated using an interception method based on ODBC. For example, when DBUAI-ODBC connects to the target database, it utilizes the database operation APIs (interfaces) provided by the native driver to perform the database connection.
[0047] It is understood that the first driver management refers to the native driver manager of the application when connecting to the database, and the second driver management is the technical solution that can implement DBUAI-ODBC and DBUAI-ODBC in the embodiments of the present invention. It can be a driver manager or an equivalent technical solution that implements driver management.
[0048] S200 creates a second driver management system based on the type of driver manager and the type of application, and connects to the target database through the second driver management system.
[0049] In some embodiments, reference Figure 2 A schematic diagram of the connection process for the second driver management based on JDBC, which includes, but is not limited to, steps S210~S220:
[0050] S210, determine the type of application;
[0051] S220, when the application type is JAVA, the configuration file of the target database is obtained through the second driver management, the JAVA reflection mechanism and the configuration file are loaded into the first driver management, and a connection with the target database is established through the first driver management;
[0052] When the application type is one of C / C++, PHP, or PYTHON, the configuration file of the target database is obtained through the second driver management, the first driver management is obtained and loaded according to the configuration file, and a connection with the target database is established according to the database operation interface in the first driver management.
[0053] In some embodiments, two second driver managers are proposed, namely DBUAI-JDBC and DBUAI-ODBC, wherein DBUAI-JDBC is the driver manager selected when the application type is JAVA, and DBUAI-ODBC is the driver manager selected when the application type is C / C++, PHP and PYTHON.
[0054] For example, when DBUAI-JDBC connects to the target database, the JDBC driver manager can load the DBUAI-JDBC driver using JAVA's reflection mechanism. The DBUAI-JDBC driver then interacts with the database through the database's native JDBC driver based on the read target database connection configuration information.
[0055] For example, when DBUAI-ODBC connects to a target database, the DBUAI-ODBC driver manager first reads the target database connection configuration, obtains and loads the database's native ODBC driver, and uses its provided database operation API to execute the database connection.
[0056] S300 parses and transforms the first query field through the second driver management to obtain the second query field, and then accesses the target database based on the first driver management, the second driver management, and the second query field to obtain the query result.
[0057] In some embodiments, reference Figure 3The diagram illustrates the data query process managed by the second JDBC driver. The DBUAI-JDBC driver fully complies with the JDBC standard. The application interacts with the target database through the DBUAI-JDBC driver. First, the DBUAI-JDBC driver identifies the target database by reading the configuration file, loads the target database's native JDBC driver, and then establishes a connection. After obtaining the source SQL statement, it calls the core parsing and transformation interface to parse and transform the source SQL statement. The transformed SQL statement is then sent to the target database for execution via the database's native JDBC driver. Finally, the DBUAI-JDBC driver receives the execution result of the SQL statement and returns it to the application.
[0058] In some embodiments, the parsing and conversion interface is used to parse the first query field, obtain query information, and convert the first query field according to the syntax rules of the target database and the query information to obtain a second query field that conforms to the query rules of the target database.
[0059] In some embodiments, reference Figure 4 The diagram shows a data query process based on ODBC-based second driver management. The DBUAI-ODBC driver manager first reads the target database connection configuration, obtains and loads the database's native ODBC driver, uses its provided database operation API to execute the database connection, and obtains the application's SQL statements.
[0060] In some embodiments, JNI technology is used to enable the DBUAI-ODBC driver manager (written in C) to call the Java-written parsing and conversion interface. This technology first reads the location of the Java environment and the location of the parsing and conversion interface's JAR file, then creates a JNI virtual machine. After creation, the DBUAI-ODBC driver manager loads the parsing and conversion interface, parses and converts the acquired source SQL statement, and then sends the converted SQL statement to the target database for execution via the database's native ODBC driver. Finally, the DBUAI-ODBC driver manager receives the execution result of the SQL statement and returns it to the application.
[0061] S400 retrieves query results through the second drive management and returns them to the application.
[0062] In some embodiments, reference Figure 5 The diagram shows the overall architecture for accessing the differentiated database. In this embodiment of the invention, the DBUAI-JDBC driver manager and the DBUAI-ODBC driver manager are respectively set in the driver layer and the driver management layer. The compatibility of the DBUAI-ODBC driver manager is considered when designing the database connection configuration file.
[0063] The DBUAI-JDBC driver manager and DBUAI-ODBC driver manager adopt a standardized configuration method to uniformly configure multiple databases with different data sources. In addition, when retrieving query fields from the application, the timing of retrieving query fields and the location of calling the parsing and conversion interface are configured to improve the compatibility of the DBUAI-JDBC driver manager and DBUAI-ODBC driver manager.
[0064] Figure 6 This is a diagram of an access device for a differentiated database according to an embodiment of the present invention. The device includes an access module 610, a connection module 620, an interception module 630, and a return module 640.
[0065] The system includes the following modules: an access module, which acquires the application's access request to the target database, determines the type of the accessed application and the first query field, and uses the application type to determine the first driver manager accessing the target database; a connection module, which creates a second driver manager based on the type of the driver manager and the type of the application, and connects to the target database through the second driver manager; an interception module, which parses and transforms the first query field through the second driver manager to obtain the second query field, and performs access to the target database based on the first driver manager, the second driver manager, and the second query field to obtain the query result; and a return module, which acquires the query result through the second driver manager and returns it to the application.
[0066] For example, with the cooperation of the access module, connection module, interception module, and return module in the device, the embodiment device can implement any of the aforementioned differentiated database access methods, namely, obtaining the application's access request to the target database, determining the type of the accessed application and the first query field, the application type being used to determine the first driver management for accessing the target database; creating a second driver management based on the type of the driver management and the type of the application, connecting to the target database through the second driver management; parsing and transforming the first query field through the second driver management to obtain the second query field; performing access to the target database based on the first driver management, the second driver management, and the second query field to obtain the query result; and obtaining the query result through the second driver management and returning it to the application. The beneficial effects of this invention are as follows: For JDBC driver managers used by JAVA applications, and ODBC driver managers corresponding to C / C++, PHP, and PYTHON language applications, the invention loads the target database connection configuration information read by a second JDBC-based driver manager, then interacts with the database through the database's native JDBC driver. Furthermore, the second ODBC-based driver manager adds interception of access query fields, calls the statement parsing and conversion interface to convert the query fields, and completes data querying and return through the native driver manager. This eliminates the need to modify the native driver manager, avoids direct access to the target database by the application, improves the security of the target database, and enhances the compatibility of accessing and storing data in the target database.
[0067] This invention also provides an electronic device, which includes a processor and a memory;
[0068] The memory stores the program;
[0069] The processor executes a program to perform the aforementioned method for accessing the differentiated database; the electronic device has the function of carrying and running a software system for accessing the differentiated database provided in the embodiments of the present invention, such as a personal computer, minicomputer, mainframe, workstation, network or distributed computing environment, standalone or integrated computer platform, or communicating with charged particle tools or other imaging devices, etc.
[0070] This invention also provides a computer-readable storage medium storing a program that is executed by a processor to implement the differentiated database access method described above.
[0071] In some alternative embodiments, the functions / operations mentioned in the block diagrams may not occur in the order shown in the operation diagrams. For example, depending on the functions / operations involved, two consecutively shown blocks may actually be executed substantially simultaneously, or the blocks may sometimes be executed in reverse order. Furthermore, the embodiments presented and described in the flowcharts of this invention are provided by way of example to provide a more comprehensive understanding of the technology. The disclosed methods are not limited to the operations and logic flows presented herein. Alternative embodiments are contemplated in which the order of various operations is altered and sub-operations described as part of a larger operation are executed independently.
[0072] This invention also discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the aforementioned differentiated database access method.
[0073] Furthermore, although the invention has been described in the context of functional modules, it should be understood that, unless otherwise stated, one or more of the described functions and / or features may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the invention. Rather, given the properties, functions, and internal relationships of the various functional modules in the apparatus disclosed herein, the actual implementation of the module will be understood within the scope of conventional skill of an engineer. Therefore, those skilled in the art can implement the invention as set forth in the claims using ordinary techniques without excessive experimentation. It is also understood that the specific concepts disclosed are merely illustrative and not intended to limit the scope of the invention, which is determined by the full scope of the appended claims and their equivalents.
[0074] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0075] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-including system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0076] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the program can be printed, because the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0077] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0078] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0079] Although embodiments of the invention have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.
[0080] The above is a detailed description of the preferred embodiments of the present invention, but the present invention is not limited to the embodiments described. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.
Claims
1. A method for accessing a differentiated database, characterized in that, include: Obtain the application's access request to the target database, determine the type of the accessed application and the first query field, wherein the application type is used to determine the first driver management for accessing the target database; A second driver management is created based on the type of the first driver management and the type of the application, and the target database is connected through the second driver management. The first query field is obtained through the second driver management, and the first query field is parsed and transformed using a parsing and transformation interface to obtain the second query field. The second query field is then used to perform a query through the first driver management and the target database to obtain the query result. The query results are obtained through the second driver management and returned to the application; The step of creating a second driver management system based on the type of the first driver management system and the type of the application includes: When the application type is JAVA, the second driver management is generated based on JDBC using a virtual interface. When the application type is one of C / C++, PHP and PYTHON, the second driver management is generated based on ODBC using an interception method. The step of creating a second driver manager based on the type of the first driver manager and the type of the application, and connecting to the target database through the second driver manager, includes: When the application type is JAVA, the configuration file of the target database is obtained through the second driver management, the first driver management is loaded using the JAVA reflection mechanism and the configuration file, and a connection with the target database is established through the first driver management. When the application is of type C / C++, PHP, or PYTHON, the configuration file of the target database is obtained through the second driver management, the first driver management is obtained and loaded according to the configuration file, and a connection with the target database is established according to the database operation interface in the first driver management.
2. The method for accessing a differentiated database according to claim 1, characterized in that, The parsing and conversion interface is used to parse the first query field, obtain query information, and convert the first query field according to the syntax rules of the target database and the query information to obtain the second query field that conforms to the query rules of the target database.
3. The method for accessing a differentiated database according to claim 1, characterized in that, Also includes: When the application is of type C / C++, PHP, or PYTHON, the parsing and conversion interface is loaded by the JNI virtual machine through the second driver management to complete the parsing and conversion of the first query field.
4. An access device for a differentiated database, characterized in that, include: The access module is used to obtain the application's access request to the target database, determine the type of the accessed application and the first query field, wherein the application type is used to determine the first driver management for accessing the target database; The connection module is used to create a second driver management based on the type of the first driver management and the type of the application, and connect to the target database through the second driver management; The interception module is used to obtain the first query field through the second driver management, parse and transform the first query field using a parsing and transformation interface to obtain the second query field, and execute a query on the second query field through the first driver management and the target database to obtain the query result; The return module is used to obtain the query results through the second driver management and return them to the application. The step of creating a second driver management system based on the type of the first driver management system and the type of the application includes: When the application type is JAVA, the second driver management is generated based on JDBC using a virtual interface. When the application type is one of C / C++, PHP and PYTHON, the second driver management is generated based on ODBC using an interception method. The step of creating a second driver manager based on the type of the first driver manager and the type of the application, and connecting to the target database through the second driver manager, includes: When the application type is JAVA, the configuration file of the target database is obtained through the second driver management, the first driver management is loaded using the JAVA reflection mechanism and the configuration file, and a connection with the target database is established through the first driver management. When the application is of type C / C++, PHP, or PYTHON, the configuration file of the target database is obtained through the second driver management, the first driver management is obtained and loaded according to the configuration file, and a connection with the target database is established according to the database operation interface in the first driver management.
5. An electronic device, characterized in that, Including the processor and memory; The memory is used to store programs; The processor executes the program to implement the method for accessing the differentiated database as described in any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The storage medium stores a program that is executed by a processor to implement the method for accessing the differentiated database as described in any one of claims 1-3.
Citation Information
Patent Citations
Method and system for C / C + + application program of ARM platform to access database
CN112364087A