Database management method and related device
By dynamically configuring query fields and preset cache mechanisms, the database management complexity and error problems caused by the single JDBC function are solved, and the flexibility and efficiency of database operations are improved.
Patent Information
- Application Number
- CN202411143232.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-20
- Publication Date
- 2024-12-13
AI Technical Summary
The database management functions provided by JDBC are relatively single, which leads to developers need to manually write code to handle tedious tasks, which increases the complexity and possibility of errors in database management.
Build target query statements by dynamically configuring query fields, and use preset caches to store query statements and results to reduce duplicate construction and frequent access to the database, and realize automatic resource management.
It improves the flexibility and reusability of query statements, reduces the complexity and possibility of database operations, and optimizes resource utilization and response speed.
Smart Images

Figure CN119127836A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a database management method and related devices. Background Art
[0002] With the rapid development of information technology and the advent of the big data era, data processing needs have become increasingly complex and diverse. These changes have put forward higher requirements for database management tools and methods, prompting them to continue to evolve to meet new challenges.
[0003] JDBC (Java Database Connectivity) is a long-standing and widely used database connection framework on the Java platform, providing Java developers with a standardized way to manage various relational databases.
[0004] However, the functions provided by JDBC are relatively simple, and developers need to manually write code to handle a lot of tedious work, which increases the complexity of database management and the possibility of errors. Summary of the invention
[0005] In view of the above problems, the present application provides a database management method and related devices to reduce the complexity and error possibility of database management. The specific scheme is as follows:
[0006] The first aspect of the present application provides a database management method, comprising:
[0007] In response to a user's query request for a target database, a connection is established with the target database, and a query statement is established, wherein the query statement includes a query field;
[0008] Based on the query request, the query field is configured to obtain a target query statement, the target query statement is configured to a preset cursor, and the configured preset cursor is stored in a first preset cache;
[0009] Execute the target query statement in the first preset cache to obtain a query result, and store the query result in a second preset cache;
[0010] Based on the query request, encapsulate the query result and return the encapsulated query result to the user;
[0011] The connection with the target database is disconnected, and the first preset cache and the second preset cache are released.
[0012] In a possible implementation, the query field includes a table name placeholder, a common parameter placeholder, and a Where condition parameter placeholder;
[0013] The configuring the query fields based on the query request to obtain a target query statement includes:
[0014] Save the table name of the query request to LinkedList <string>JTAB cache, and based on the LinkedList <string>The table name in the JTAB cache configures the table name placeholder to obtain a first query statement;
[0015] Save the common parameters of the query request to LinkedList <string>JPAR caching and based on the LinkedList <object>The common parameters in the JPAR cache configure the common parameter placeholders to obtain a second query statement;
[0016] Save the common parameters of the query request to LinkedList <object>JWHE cache, and based on the LinkedList <object>The Where condition parameter in the JWHE cache configures the Where condition parameter placeholder to obtain a third query statement;
[0017] The first query statement, the second query statement and the third query statement are combined to obtain the target query statement.
[0018] In a possible implementation, configuring the target query statement to a preset cursor includes:
[0019] Based on the target query statement, determine the order of target parameters, where the target parameters include the common parameters and the Where condition parameters;
[0020] The LinkedList <object>JPAR Cache and the LinkedList <object>The target parameters in the JWHE cache are configured one by one to the preset cursor in the order, and the Where condition parameters are configured one by one to the preset cursor in the order.
[0021] In a possible implementation, encapsulating the query result based on the query request includes:
[0022] Based on the query request, determine whether to obtain all the data of the target query field, where all the target query fields include the table name, the common parameters, and / or the Where condition parameters;
[0023] If not all data of the target query field is obtained, the query result is encapsulated using the Jwer.getRs method;
[0024] If all the data of the target query field is obtained, the query result is encapsulated using the Jwer.getRss method.
[0025] A second aspect of the present application provides a database management device, comprising:
[0026] An establishing unit, configured to establish a connection with a target database and establish a query statement in response to a query request from a user to the target database, wherein the query statement includes a query field;
[0027] A configuration unit, configured to configure the query field based on the query request to obtain a target query statement, configure the target query statement to a preset cursor, and store the configured preset cursor to a first preset cache;
[0028] An execution unit, configured to execute the target query statement in the first preset cache, obtain a query result, and store the query result in a second preset cache;
[0029] An encapsulation unit, configured to encapsulate the query result based on the query request, and return the encapsulated query result to the user;
[0030] A releasing unit is used to disconnect from the target database and release the first preset cache and the second preset cache.
[0031] In a possible implementation, the query field includes a table name placeholder, a common parameter placeholder, and a Where condition parameter placeholder;
[0032] The configuration unit for configuring the query field based on the query request to obtain the target query statement includes:
[0033] The first configuration subunit is used to save the table name of the query request to the LinkedList <string>JTAB cache, and based on the LinkedList <string>The table name in the JTAB cache configures the table name placeholder to obtain a first query statement;
[0034] The second configuration subunit is used to save the common parameters of the query request to the LinkedList <string>JPAR caching and based on the LinkedList <object>The common parameters in the JPAR cache configure the common parameter placeholders to obtain a second query statement;
[0035] The third configuration subunit is used to save the common parameters of the query request to the LinkedList <object>JWHE cache, and based on the LinkedList <object>The Where condition parameter in the JWHE cache configures the Where condition parameter placeholder to obtain a third query statement;
[0036] The combining subunit is used to combine the first query statement, the second query statement and the third query statement to obtain the target query statement.
[0037] In a possible implementation, the configuring unit for configuring the target query statement to a preset cursor includes:
[0038] A determination subunit, configured to determine an order of target parameters based on the target query statement, wherein the target parameters include the common parameters and the Where condition parameters;
[0039] The fourth configuration subunit is used to configure the LinkedList <object>JPAR Cache and the LinkedList <object>The target parameters in the JWHE cache are configured one by one to the preset cursor in the order, and the Where condition parameters are configured one by one to the preset cursor in the order.
[0040] A third aspect of the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the database management method of the first aspect or any implementation of the first aspect.
[0041] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0042] The memory is used to store computer programs;
[0043] The processor is used to execute the computer program so that the electronic device can implement the database management method of the above-mentioned first aspect or any implementation manner of the first aspect.
[0044] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the database management method of the above-mentioned first aspect or any implementation method of the first aspect.
[0045] By means of the above technical scheme, the present application provides a database management method and related devices, which construct a target query statement by dynamically configuring the query field according to the query request, which means that there is no need to write an independent SQL statement for each query, thereby improving the flexibility and reusability of the query statement. The first preset cache is used to store the configured query statement, avoiding the overhead of repeatedly building the same query statement; the second preset cache is used to store the query results, so that subsequent requests for the same query can directly obtain the results from the cache without accessing the database again, thereby improving the response speed and reducing the performance problems caused by frequent access to the database. After encapsulating the query results and returning them to the user, the connection with the database is automatically disconnected and the cache resources are released, which can significantly reduce the database load and optimize resource utilization. Therefore, the dynamic construction of query statements, application of cache mechanisms and resource management in this solution reduce the complexity of database operations and the possibility of errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0047] Figure 1 A flowchart of a database management method provided in an embodiment of the present application;
[0048] Figure 2 A schematic diagram of a process of configuring a query field based on a query request to obtain a target query statement provided in an embodiment of the present application;
[0049] Figure 3 A schematic diagram of the structure of a database management device provided in an embodiment of the present application;
[0050] Figure 4 A schematic diagram of the hardware structure of a database management device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0051] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.
[0052] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0053] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0054] In order to reduce the complexity and error possibility of database operations, the present application provides a database management method. The database management method provided by the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0055] Please see attached Figure 1 , Figure 1 A flowchart of a database management method provided in an embodiment of the present application. The method may include the following steps:
[0056] Step S101: in response to a user's query request to a target database, a connection is established with the target database, and a query statement is established, wherein the query statement includes a query field.
[0057] In this application, the Jwer.newSql method can be used to create a query statement and save the query statement to the StringBuilder JSQL cache in the Jwer class.
[0058] It should be noted that the query fields include table name placeholders, common parameter placeholders, and Where condition parameter placeholders.
[0059] There are two ways to establish a connection with the target database. The first method requires providing database connection information, including the database address, user name and password, i.e. Jwer (String url, String user, String password). The Jwer class will use this information to establish a connection with the database. The other method requires passing an existing database connection (Connection object) to the Jwer class, i.e. Jwer (Connection conn). Jwer will not initiate a connection again, but directly use the connection. The connection result of the target database can be saved in the Connection JCON cache in the Jwer class.
[0060] For ease of understanding, the following example is used: Create a query statement: jwer.newSql("select*from#as t1,#ast2 where t1.name=t2.name”), and save the string "select*from#as t1,#as t2 where t1.name=t2.name" to the StringBuilder JSQL cache in the Jwer class. The "#" symbol is a table name placeholder so that the specified position can be identified and replaced during subsequent execution.
[0061] Step S102: Based on the query request, query fields are configured to obtain a target query statement, the target query statement is configured to a preset cursor, and the configured preset cursor is stored in a first preset cache.
[0062] In the present application, based on the query request, lombok syntax can be used to splice statements to configure the query fields. The last operation is when executing the Sql statement execute or executing the query executeQuery or executing the update Sql statement executeUpdate, it is confirmed that the user input has ended, and it starts to be sorted according to the obtained content to obtain the target query statement.
[0063] It should be noted that Java objects allow the creation of methods and parameters, and the calling of methods through the ". " symbol. Therefore, after the method is executed, the object is returned, and the next call connection can be realized again using the ". " symbol.
[0064] To make it easier to understand, let’s take the following example: in Jwer.newSql(...).setTables(...).setvalues(...).executeQuery(), the Jwer class methods newSql(), setTables(), setvalues(), and executeQuery() are all designed to return a reference to the Jwer object itself after execution (i.e., return this;). There is no need to create a new Jwer object instance for each method call or store its result in a temporary variable. These methods can be called continuously in a single expression.
[0065] This calling method only configures the query parameters and does not modify the original query statement. Therefore, jwer directly calls the native JDBC PreparedStatement class, configures the target query statement to the preset cursor, and calls the native setObject method in the object in a loop to configure the parameters.
[0066] Specifically, the order of target parameters can be determined based on the target query statement. The target parameters include common parameters and Where condition parameters. <object>JPAR Cache and LinkedList <object>The target parameters in the JWHE cache are configured to the preset cursor one by one in sequence, and the Where condition parameters are configured to the preset cursor one by one in sequence.
[0067] Step S103: Execute the target query statement in the first preset cache, obtain the query result, and store the query result in the second preset cache.
[0068] In the present application, the query method executeQuery provided by JDBC can be called to execute the target query statement in the first preset cache, obtain the query result, and save the query result in the second preset cache of the jwer object.
[0069] Step S104: Based on the query request, the query result is packaged and the packaged query result is returned to the user.
[0070] In this application, in order to facilitate users to obtain these query results, there are multiple methods to encapsulate the query results and return them to the users.
[0071] Specifically, based on the query request, it can be determined whether to obtain all the data of the target query field, where all the target query fields include the table name, the common parameters, and / or the Where condition parameters. If not all the data of the target query field is obtained, the query result is encapsulated using the Jwer.getRs method; if all the data of the target query field is obtained, the query result is encapsulated using the Jwer.getRss method.
[0072] Among them, the getRs() method in the Jwer.getRs method can use the native ResultSetMetaData class to obtain all the target query fields in the query results, read the first data of all the target query fields, and encapsulate all the target query fields of the first data into JSON format for return. For ease of understanding, please refer to Table 1 for details. Calling the getRs() method will automatically obtain all the target query fields "school name", "school address", "school phone number" and "school email address", read the first data "aa school", "Hainan ××", "130××" and "××@163.com", and return it to the user.
[0073] Table 1
[0074]
[0075] The getRs(String...keys) method in the Jwer.getRs method can match the target query field in the first data according to the key list provided by the user, read the first data of the matching target query field, and encapsulate the matching target query field of the first data into JSON format for return. For ease of understanding, please refer to Table 1 for details. Calling getRs("school name") will automatically obtain the matching target query field "school name", read the first data "aa school", and return it to the user.
[0076] The getRss() method in the Jwer.getRss method is similar to the getRs() method. It obtains all target query fields, reads all data of all target query fields, encapsulates each data into the JSONObject format, and adds it to the JSONArray type and returns it to the user.
[0077] The getRss(String...keys) method in the Jwer.getRss method is similar to the getRs(String...keys) method. It obtains the matching target query field, reads all the data of the matching target query field, encapsulates each piece of data into the JSONObject format, and adds them to the JSONArray type and returns them to the user.
[0078] Step S105: disconnecting from the target database and releasing the first preset cache and the second preset cache.
[0079] In this application, the native interface AutoCloseable that comes with Java is inherited. After use, the close() method in the object is automatically called to close the database connection, cursor, and query results, ensuring that they can be closed correctly after use, thereby releasing resources.
[0080] In summary, the embodiment of the present application provides a database management method, which constructs a target query statement by dynamically configuring the query field according to the query request, which means that there is no need to write an independent SQL statement for each query, thereby improving the flexibility and reusability of the query statement. The first preset cache is used to store the configured query statement, avoiding the overhead of repeatedly building the same query statement; the second preset cache is used to store the query results, so that subsequent requests for the same query can directly obtain the results from the cache without accessing the database again, thereby improving the response speed and reducing the performance problems caused by frequent access to the database. After encapsulating the query results and returning them to the user, the connection with the database is automatically disconnected and the cache resources are released, which can significantly reduce the database load and optimize resource utilization. Therefore, the dynamic construction of query statements, application of cache mechanisms and resource management in this solution reduce the complexity of database operations and the possibility of errors.
[0081] In order to solve the above problems, the embodiment of the present application provides a method for configuring the query fields based on the query request to obtain the target query statement. The following is a detailed introduction of the method for configuring the query fields based on the query request to obtain the target query statement in the embodiment of the present application in conjunction with the accompanying drawings.
[0082] Reference Figure 2 , Figure 2 A process diagram of a method for configuring a query field based on a query request to obtain a target query statement provided in an embodiment of the present application, such as Figure 2 As shown, a data processing method provided in an embodiment of the present application may include steps 201 to 204, and these steps are described in detail below.
[0083] Step 201: Save the table name of the query request to LinkedList <string>JTAB cache, based on LinkedList <string>The table name in the JTAB cache configures the table name placeholder to obtain the first query statement.
[0084] In this application, Jwer.setTable method is used, lombok statement is used, based on LinkedList <string>The table name in the JTAB cache is configured with the table name placeholder in the query field to obtain the first query statement.
[0085] For ease of understanding, the following example is used: only configure the table name placeholder of the query field: jwer.newSql("select*from#as t1,#as t2 where t1.name=t2.name”).setTables("school”,"student”).executeQuery().
[0086] Specifically, save the two table names "school" and "student" to the LinkedList in the Jwer class <string>JTAB cache. jwer will first traverse the cached query statement, that is, "select*from#as t1,#as t2 wheret1.name=t2.name". At this time, it is found that there are two table name placeholders "#" in the query statement, so the first table name placeholder is used with LinkedList <string>The first table name "school" in the JTAB cache is replaced, and the second table name placeholder is replaced with LinkedList <string>The second table name "student" in the JTAB cache is replaced to obtain the first query statement "select * from school as t1, student as t2 where t1.name = t2.name".
[0087] Step 202: Save the common parameters of the query request to LinkedList <string>JPAR cache, based on LinkedList <object>The common parameters in the JPAR cache configure the common parameter placeholders to obtain the second query statement.
[0088] In this application, Jwer.setTable method is used, lombok statement is used, based on LinkedList <object>Ordinary parameters in the JPAR cache are configured for the ordinary parameters in the query fields to obtain a second query statement.
[0089] For ease of understanding, the following is an example: Only configure the ordinary parameter placeholder in the query field. jwer.newSql("select*from student where name=?and id=?and classroom=?").setValues("张三”,"4600031990xxxxx”,"601”).executeQuery().
[0090] Specifically, save the three ordinary parameters of "张三”,"4600031990xxxxx” and "601” to the LinkedList in the Jwer class <object>JPAR cache. jwer will first traverse the cached query statement, that is, "select * from student where name =? and id =? and classroom =?", and then find that there are three common parameter placeholders "?" in the query statement, so the first common parameter placeholder is LinkedList. <object>The first common parameter "Zhang San" of the JPAR cache is replaced, and the second common parameter placeholder is replaced with LinkedList <object>The second common parameter "4600031990xxxxx" of the JPAR cache is replaced, and the third common parameter placeholder is replaced with LinkedList <object>The third common parameter "601" of the JPAR cache is replaced to obtain the second query statement "select * from student where name = Zhang San and id = 4600031990xxxxx and classroom = 601".
[0091] However, the above method can be used when it is clear that three common parameters are needed for query. If it is not clear how many common parameters are needed for query, it is necessary to first judge the common parameters and determine the target query statement based on the common parameters. For example: use "select * from student where 1 = 1" to check which common parameters exist (i.e. not empty or not null). If name = Zhang San, id = null, classromm = null, then only all students with the name Zhang San are searched, and the second query statement is determined to be "select * from student where name = Zhang San".
[0092] Step 203: Save the common parameters of the query request to LinkedList <object>JWHE cache, based on LinkedList <object>The Where condition parameter in the JWHE cache configures the Where condition parameter placeholder to obtain a third query statement.
[0093] In this application, using Jwer.criteria method, using lombok statement, based on LinkedList <object>The Where condition parameters in the JWHE cache are configured for the Where condition parameters in the query fields to obtain the third query statement.
[0094] For ease of understanding, the following example is given: Only configure the Where condition parameters and ordinary parameters in the query fields. jwer.newSql("select*from student where name=?”).criteria("and”,"id=?”,"123”).setValues("张三”).executeQuery().
[0095] Specifically, save the three Where condition parameters of "and”, "id=?” and "123” to the LinkedList in the Jwer class <object>JWHE cache, "Zhang San" a common parameter is saved to LinkedList in Jwer class <object>JPAR cache. In actual use, the order of these parameters cannot be confirmed, so it is necessary to distinguish between where condition parameters and common parameters. You can replace the "?" in "id=?" with "$", that is, the actual LinkedList <object>The data cached by JWHE is "and", "id=$" and "123".
[0096] Jwer will give priority to processing the data in the where condition cache to determine whether the value of id exists and is valid (that is, not empty and not null). If it is valid, the query statement will be spliced. The splicing result is as follows: "select * from student where name =? and id = $", jwer starts to traverse the query statement. At this time, it is found that there is a common parameter placeholder "?" and a where condition parameter placeholder "$" in the query statement. Therefore, the first common parameter placeholder "?" is used with LinkedList <object>The first common parameter "Zhang San" of the JPAR cache is replaced, and the first where condition parameter placeholder "$" is replaced with LinkedList <object>The first Where condition parameter "123" that is not involved in the splicing in the JWHE cache is replaced to obtain the third query statement "select * from student where name = Zhang San and id = 123".
[0097] Step 204: Combine the first query statement, the second query statement, and the third query statement to obtain a target query statement.
[0098] To make it easier to understand, here are some examples:
[0099] Configure the table name, common parameters and Where condition parameters of the query field jwer.newSql("select*from#where name=?").setTables("student").criteria("and","id=?","123").setValues("Zhang San").executeQuery().
[0100] Specifically, save the configured table name "student" to the LinkedList in the Jwer class <string>JTAB cache saves the three Where condition parameters "and", "id=$" and "123" to the LinkedList in the Jwer class <object>JWHE cache, "Zhang San" a common parameter is saved to LinkedList in Jwer class <object>JPAR caching.
[0101] jwer will first traverse the cached query statement, that is, "select * from # where name =?", and then find that there is a table name placeholder "#" in the query statement, so the table name placeholder is used with LinkedList <string>JTAB cache table name "student" is replaced, and then Jwer will process the data in the where condition cache to determine whether the value of id exists (that is, not empty or not null). If it exists, it means that the user has entered a valid value, and the query statement will be spliced. The splicing result is as follows: "select * from student where name =? and id = $", jwer begins to traverse the query statement, and then finds that there is a common parameter placeholder "?" and a where parameter placeholder "$" in the query statement. Therefore, the first common parameter placeholder "?" is replaced with LinkedList <object>The first common parameter "Zhang San" of the JPAR cache is replaced, and the first where parameter placeholder "$" is replaced with LinkedList <object>The first Where condition parameter "123" in the JWHE cache that is not involved in the splicing is replaced to obtain the target query statement "select * from student where name = Zhang San and id = 123".
[0102] A database management method provided in an embodiment of the present application is introduced above, and a device for executing the above database management method will be introduced below.
[0103] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of a database management device provided in an embodiment of the present application. Figure 3 As shown, the database management device comprises:
[0104] The establishing unit 11 is used to establish a connection with the target database and establish a query statement in response to a query request of a user to the target database, wherein the query statement includes a query field.
[0105] The configuration unit 12 is used to configure the query field based on the query request to obtain a target query statement, configure the target query statement to a preset cursor, and store the configured preset cursor to a first preset cache.
[0106] The execution unit 13 is used to execute the target query statement in the first preset cache, obtain a query result, and store the query result in a second preset cache.
[0107] The encapsulation unit 14 is used to encapsulate the query result based on the query request and return the encapsulated query result to the user.
[0108] The releasing unit 15 is used to disconnect from the target database and release the first preset cache and the second preset cache.
[0109] In a possible implementation, the query field includes a table name placeholder, a common parameter placeholder, and a Where condition parameter placeholder.
[0110] The configuration unit 12 for configuring the query field based on the query request to obtain the target query statement includes:
[0111] The first configuration subunit is used to save the table name of the query request to the LinkedList <string>JTAB cache, and based on the LinkedList <string>The table name in the JTAB cache configures the table name placeholder to obtain a first query statement.
[0112] The second configuration subunit is used to save the common parameters of the query request to the LinkedList <string>JPAR caching and based on the LinkedList <object>The common parameters in the JPAR cache configure the common parameter placeholders to obtain a second query statement.
[0113] The third configuration subunit is used to save the common parameters of the query request to the LinkedList <object>JWHE cache, and based on the LinkedList <object>The Where condition parameter in the JWHE cache configures the Where condition parameter placeholder to obtain a third query statement.
[0114] The combining subunit is used to combine the first query statement, the second query statement and the third query statement to obtain the target query statement.
[0115] In a possible implementation, the configuring unit 12 for configuring the target query statement to a preset cursor includes:
[0116] The determination subunit is used to determine the order of target parameters based on the target query statement, and the target parameters include the common parameters and the Where condition parameters.
[0117] The fourth configuration subunit is used to configure the LinkedList <object>JPAR Cache and the LinkedList <object>The target parameters in the JWHE cache are configured one by one to the preset cursor in the order, and the Where condition parameters are configured one by one to the preset cursor in the order.
[0118] In a possible implementation, the encapsulation unit 14 that encapsulates the query result based on the query request includes:
[0119] The judgment subunit is used to judge whether to obtain all the data of the target query field based on the query request, and the all target query fields include the table name, the common parameters, and / or the Where condition parameters.
[0120] The first encapsulation subunit is used to encapsulate the query result by using the Jwer.getRs method if not all data of the target query field is obtained.
[0121] The second encapsulation subunit is used to encapsulate the query result by using the Jwer.getRss method if all the data of the target query field is obtained.
[0122] The present application also provides an electronic device in an embodiment. Figure 4 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic device in the embodiments of the present application may include but is not limited to fixed terminals such as mobile phones, notebook computers, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 4 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0123] like Figure 4 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage device 408 to a random access memory (RAM) 403. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 403. The processing device 401, the ROM 402, and the RAM 403 are connected to each other via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0124] Typically, the following devices may be connected to the I / O interface 405: an input device 406 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 407 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 408 including, for example, a memory card, a hard disk, etc.; and a communication device 409. The communication device 409 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0125] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any database management method provided in the embodiment of the present application.
[0126] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any database management method provided in an embodiment of the present application.
[0127] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0128] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0129] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0130] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.< / object> < / object> < / object> < / object> < / object> < / string> < / string> < / string> < / object> < / object> < / string> < / object> < / object> < / string> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / string> < / string> < / string> < / string> < / string> < / string> < / string> < / object> < / object> < / object> < / object> < / object> < / object> < / object> < / string> < / string> < / string> < / object> < / object> < / object> < / object> < / object> < / string> < / string> < / string>
Claims
1. A database management method, characterized in that: include: In response to a user's query request to a target database, a connection is established with the target database, and a query statement is established, wherein the query statement includes a query field; Based on the query request, the query field is configured to obtain a target query statement, the target query statement is configured to a preset cursor, and the configured preset cursor is stored in a first preset cache; Execute the target query statement in the first preset cache to obtain a query result, and store the query result in a second preset cache; Based on the query request, encapsulate the query result and return the encapsulated query result to the user; The connection with the target database is disconnected, and the first preset cache and the second preset cache are released.
2. The database management method according to claim 1, characterized in that: The query field includes a table name placeholder, a common parameter placeholder, and a Where condition parameter placeholder; The configuring the query fields based on the query request to obtain a target query statement includes: Save the table name of the query request to LinkedList <string>JTAB cache, and based on the LinkedList <string> The table name in the JTAB cache configures the table name placeholder to obtain a first query statement;< / string> < / string> Save the common parameters of the query request to LinkedList <string>JPAR caching and based on the LinkedList <object>The common parameters in the JPAR cache configure the common parameter placeholders to obtain a second query statement; Save the common parameters of the query request to LinkedList <object>JWHE cache, and based on the LinkedList <object>The Where condition parameter in the JWHE cache configures the Where condition parameter placeholder to obtain a third query statement; The first query statement, the second query statement and the third query statement are combined to obtain the target query statement.
3. The database management method according to claim 2, characterized in that: The configuring the target query statement to a preset cursor includes: Based on the target query statement, determine the order of target parameters, where the target parameters include the common parameters and the Where condition parameters; The LinkedList <object>JPAR Cache and the LinkedList <object>The target parameters in the JWHE cache are configured one by one to the preset cursor in the order, and the Where condition parameters are configured one by one to the preset cursor in the order.
4. The database management method according to claim 2, characterized in that: The encapsulating the query result based on the query request includes: Based on the query request, determine whether to obtain all the data of the target query field, where all the target query fields include the table name, the common parameters, and / or the Where condition parameters; If not all data of the target query field is obtained, the query result is encapsulated using the Jwer.getRs method; If all the data of the target query field is obtained, the query result is encapsulated using the Jwer.getRss method.
5. A database management device, characterized in that: include: An establishing unit, configured to establish a connection with a target database and establish a query statement in response to a query request from a user to the target database, wherein the query statement includes a query field; A configuration unit, configured to configure the query field based on the query request to obtain a target query statement, configure the target query statement to a preset cursor, and store the configured preset cursor to a first preset cache; An execution unit, configured to execute the target query statement in the first preset cache, obtain a query result, and store the query result in a second preset cache; An encapsulation unit, configured to encapsulate the query result based on the query request, and return the encapsulated query result to the user; A releasing unit is used to disconnect from the target database and release the first preset cache and the second preset cache.
6. The database management device according to claim 5, characterized in that: The query field includes a table name placeholder, a common parameter placeholder, and a Where condition parameter placeholder; The configuration unit for configuring the query field based on the query request to obtain the target query statement includes: The first configuration subunit is used to save the table name of the query request to the LinkedList <string>JTAB cache, and based on the LinkedList <string>The table name in the JTAB cache configures the table name placeholder to obtain a first query statement;< / string> < / string> The second configuration subunit is used to save the common parameters of the query request to the LinkedList <string>JPAR caching and based on the LinkedList <object>The common parameters in the JPAR cache configure the common parameter placeholders to obtain a second query statement; The third configuration subunit is used to save the common parameters of the query request to the LinkedList <object>JWHE cache, and based on the LinkedList <object>The Where condition parameter in the JWHE cache configures the Where condition parameter placeholder to obtain a third query statement; The combining subunit is used to combine the first query statement, the second query statement and the third query statement to obtain the target query statement.
7. The database management device according to claim 6, characterized in that: The configuration unit for configuring the target query statement to a preset cursor includes: A determination subunit, configured to determine an order of target parameters based on the target query statement, wherein the target parameters include the common parameters and the Where condition parameters; The fourth configuration subunit is used to configure the LinkedList <object>JPAR Cache and the LinkedList <object>The target parameters in the JWHE cache are configured one by one to the preset cursor in the order, and the Where condition parameters are configured one by one to the preset cursor in the order.
8. A computer program product, characterized in that The method comprises computer-readable instructions, which, when executed on an electronic device, enable the electronic device to implement the database management method as claimed in any one of claims 1 to 4.
9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the database management method as described in any one of claims 1 to 4.
10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the database management method as described in any one of claims 1 to 4. < / object> < / object> < / object> < / object> < / object> < / string> < / object> < / object> < / object> < / object> < / object> < / string>
Citation Information
Cited By
Metadata-driven book searching and recommending method based on virtual knowledge graph
CN120994712A
Metadata-driven book search and recommendation method based on virtual knowledge graph
CN120994712B
