A data processing method, system, and related equipment for database queries.
By limiting the amount of data returned by the database driver layer and controlling the number of rows in the application layer result set through a two-layer protection mechanism, the memory overflow and resource leakage problems when JdbcClient queries data are solved, thereby improving the stability and compatibility of the system.
Patent Information
- Application Number
- CN202511233004.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-01
- Publication Date
- 2025-11-14
- Estimated Expiration
- 2045-09-01
AI Technical Summary
In existing technologies, when querying data using JdbcClient to perform SQL queries, there are issues such as memory overflow and database connection resource leakage, resulting in poor system stability and compatibility.
A two-layer protection mechanism is adopted, which limits the amount of data returned by the database driver layer through anonymous implementation of PreparedStatementCallback, and controls the number of rows in the result set at the application layer. Data mapping and wrapping are performed in combination with ColumnMapRowMapper and Optional wrapper class.
It effectively reduces network transmission and memory usage, improves system stability and compatibility, and ensures cross-database compatibility and stability.
Smart Images

Figure CN120743934B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology for database queries, and more specifically, to a data processing method, system, and related equipment for database queries. Background Technology
[0002] As one of the most popular open-source frameworks on the Java platform, the Spring Framework introduced the new JdbcClient interface in version 6.1, further simplifying database operations. Developers can implement chained calls through the JdbcClient interface and the fluent API design style, making SQL queries, parameter binding, and result processing via JdbcClient more intuitive and efficient.
[0003] In existing technologies, methods for performing SQL queries using JdbcClient include obtaining the entire result set of the JdbcClient query data using a doubly linked list (list) and then taking the first element to perform the SQL query, as well as using input / output processing classes (stream), computer functions (findFirst) and JdbcClient query data to perform SQL queries.
[0004] However, using JdbcClient to retrieve the entire result set via a list and then taking the first element to query the data results in the database driver transmitting the entire result set to the application layer. This not only increases network bandwidth consumption but also loads all data into memory. When processing large result sets, this can easily lead to OutOfMemoryError (OOM) issues. Furthermore, this full-load method is severely mismatched with the business requirement of only needing the first record, resulting in poor system stability and compatibility.
[0005] Using streams in conjunction with findFirst to query data via JdbcClient allows the application layer to process data on demand, but the underlying data transmission and buffering mechanisms are not optimized, and memory consumption issues persist. More seriously, the returned stream object needs to be explicitly closed; this detail is easily overlooked and can lead to the leakage of valuable resources such as database connections, resulting in poor system stability.
[0006] Therefore, improving the stability and compatibility of the system during SQL queries using JdbcClient is a problem that this application urgently needs to solve. Summary of the Invention
[0007] In view of this, this application discloses a data processing method, system and related equipment for database queries, which aims to improve the stability and compatibility of the system during the SQL query process using JdbcClient.
[0008] To achieve the above objectives, the disclosed technical solution is as follows:
[0009] The first aspect of this application discloses a data processing method for database queries, the method comprising:
[0010] An anonymous implementation of PreparedStatementCallback is constructed through a two-layer guarantee mechanism; wherein, the two-layer guarantee mechanism is a two-layer guarantee mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set during the result set processing stage at the database application layer;
[0011] In the anonymous implementation of PreparedStatementCallback, if an SQL query result exists, the data corresponding to the SQL query result is mapped to an object;
[0012] The object is packaged using a preset packaging method.
[0013] Preferably, the anonymous implementation of PreparedStatementCallback constructed through a two-layer protection mechanism includes:
[0014] By calling the setMaxRows method of the PreparedStatement class object ps, the amount of data returned by the database driver is limited so that the maximum number of rows returned by the database driver is 1.
[0015] Control the number of rows in the result set during the result set processing stage at the database application layer;
[0016] Under the two-layer guarantee mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set, SQL query parameters are bound;
[0017] By performing an SQL query using the bound SQL query parameters, it is determined whether an SQL query result is obtained, thus completing the process of constructing an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism.
[0018] Preferably, the binding of SQL query parameters under the dual-layer guarantee mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set includes:
[0019] Under the dual-layer guarantee mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set, the anonymous implementation of PreparedStatementCallback serves as the callback interface.
[0020] An ArgumentPreparedStatementSette class object is created through the callback interface;
[0021] The SQL query parameters are bound using the ArgumentPreparedStatementSette class object.
[0022] Preferably, under the anonymous implementation of PreparedStatementCallback, if an SQL query result exists, the data corresponding to the SQL query result is mapped to an object, including:
[0023] In the anonymous implementation of PreparedStatementCallback, if there are SQL query results, the data corresponding to the SQL query results is mapped into objects using the ColumnMapRowMapper mapping tool.
[0024] Preferred options also include:
[0025] In the anonymous implementation of PreparedStatementCallback, if no SQL query result exists, a null value is returned.
[0026] Preferably, the packaging of the object using a preset packaging method includes:
[0027] The object is wrapped using the Optional wrapper class.
[0028] A second aspect of this application discloses a data processing system for database queries, the system comprising:
[0029] The construction unit is used to build an anonymous implementation of PreparedStatementCallback through a two-layer guarantee mechanism; wherein, the two-layer guarantee mechanism is a two-layer guarantee mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set during the result set processing stage at the database application layer.
[0030] The mapping unit is used to map the data corresponding to the SQL query result into an object if an SQL query result exists under the anonymous implementation of PreparedStatementCallback;
[0031] A packaging unit is used to package the object using a preset packaging method.
[0032] Preferably, the building unit includes:
[0033] The limiting module is used to limit the amount of data returned by the database driver by calling the setMaxRows method of the PreparedStatement class object ps, so that the maximum number of rows returned by the database driver is 1.
[0034] The control module is used to control the number of rows in the result set during the result set processing stage of the database application layer.
[0035] The binding module is used to bind SQL query parameters under a two-layer protection mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set;
[0036] The query judgment module is used to perform SQL queries based on the bound SQL query parameters to determine whether SQL query results are obtained, thereby completing the process of building an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism.
[0037] A third aspect of this application discloses a storage medium comprising storage instructions, wherein, when the instructions are executed, the device in which the storage medium is located is controlled to perform a data processing method for database query as described in any one of the first aspects.
[0038] The fourth aspect of this application discloses an electronic device, including a memory and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors using the data processing method for database query as described in any of the first aspects.
[0039] As can be seen from the above technical solution, this application discloses a data processing method, system, and related equipment for database queries. It constructs an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism. The two-layer protection mechanism is a two-layer protection mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set during the result set processing stage at the database application layer. Under the anonymous implementation of PreparedStatementCallback, if there are SQL query results, the data corresponding to the SQL query results is mapped to an object, and the object is wrapped using a preset wrapping method.
[0040] The beneficial effects of this application are as follows: It limits the amount of data returned at the database driver level through a two-layer protection mechanism, and controls the number of rows in the result set during the database application layer result set processing stage. This prevents issues such as some drivers, like the Statement.setMaxRows driver, from failing to take effect. By controlling the number of rows in the result set during the database application layer result set processing stage through this two-layer protection mechanism to obtain the first row of data in the result set, network transmission is reduced, performance is improved, and cross-database compatibility is ensured. This, in turn, enhances the stability and compatibility of the system during SQL queries using JdbcClient. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0042] Figure 1 This is a flowchart illustrating a data processing method for database querying disclosed in an embodiment of this application;
[0043] Figure 2 This is a schematic diagram illustrating the process of constructing an anonymous PreparedStatementCallback implementation through a two-layer protection mechanism as disclosed in the embodiments of this application;
[0044] Figure 3 This is a schematic diagram of the process for binding SQL query parameters as disclosed in an embodiment of this application;
[0045] Figure 4 This is a schematic diagram of the structure of a data processing system for database querying disclosed in an embodiment of this application;
[0046] Figure 5 This is a schematic diagram of the structure of the electronic device disclosed in the embodiments of this application. Detailed Implementation
[0047] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0048] In this application, the terms "comprising," "including," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0049] As can be seen from the background technology above, using the list method to obtain the entire result set of JdbcClient query data and then taking the first element to perform SQL query, as well as using the stream and findFirst functions for processing input and output and using JdbcClient to query data to perform SQL query, results in poor system stability and poor compatibility.
[0050] To address the aforementioned issues, this application discloses a data processing method, system, and related equipment for database queries. It employs a two-layer protection mechanism to limit the amount of data returned at the database driver level and controls the number of rows in the result set during the database application layer result set processing stage. This prevents issues with some drivers, such as the Statement.setMaxRows driver, from failing to take effect. By controlling the number of rows in the result set during the database application layer result set processing stage through this two-layer protection mechanism to obtain the first row of data in the result set, network transmission is reduced, performance is improved, and cross-database compatibility is ensured. This enhances the system's stability and compatibility during SQL queries using JdbcClient. The specific implementation is described in detail in the following embodiments.
[0051] It should be noted that the data processing method, system and related equipment for database query provided in this application can be used in fields such as data processing for database query. The above is only an example and does not limit the application field of the data processing method, system and related equipment for database query provided in this application.
[0052] refer to Figure 1 As shown in the figure, this application discloses a data processing method for database queries, which mainly includes the following steps:
[0053] S101: Construct an anonymous implementation of PreparedStatementCallback through a two-layer guarantee mechanism; the two-layer guarantee mechanism is a two-layer guarantee mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set during the result set processing stage at the database application layer.
[0054] In S101, custom queries are performed using the execute method provided by the JabcOperations class object. During the custom query process, a two-layer guarantee mechanism is used to build an anonymous implementation of PreparedStatementCallback.
[0055] At the database driver level, the amount of data returned is limited by the setMaxRows method of the PreparedStatement class object ps. At the same time, the number of rows in the result set is controlled in the result set processing stage of the database application layer using the Statement.setMaxRows(n) method in the JDBC standard interface.
[0056] By limiting the amount of data returned at the database driver level using setMaxRows, and then controlling the number of rows again at the application layer result set processing stage, this dual protection mechanism can effectively address the possibility of incomplete setMaxRows support in some older database versions, thereby improving system stability and compatibility.
[0057] It should be noted that the two-layer protection mechanism uses Statement.setMaxRows at the driver level to limit the number of transmitted messages, and also uses list.get(0) or Stream.findFirst() in the returned list or Stream to achieve the limit, preventing some drivers such as Statement.setMaxRows from not taking effect.
[0058] Further row count control is implemented at the application layer result set processing stage. This is achieved through the `setMaxRows` method in the JDBC standard interface library's `Statement` class, which limits the number of rows retrieved at a time. For example, if an SQL query in MySQL retrieves 100 rows, setting the query value to 10 means retrieving only 10 rows from MySQL each time. This would require the Java application to communicate with MySQL 10 times to obtain the entire result set. However, in this solution, only the first row of the result set needs to be retrieved. This reduces network transmission significantly, as only one row needs to be retrieved, resulting in only one retrieval and improved performance and efficiency.
[0059] Regarding cross-database compatibility, there's no need to use the `LIMIT 1` syntax, because each database has a different syntax for retrieving only the first record. For example, Sybase's syntax is `SELECT TOP 10 * FROM employees`. Using this solution's `Statement.setMaxRows` avoids compatibility issues.
[0060] Add methods such as first() to the JDBC standard interface (JdbcClient.MappedQuerySpec interface), as shown in the following code:
[0061] public interface JdbcClient {
[0062] / / ...
[0063] / **
[0064] *A specification forRowMapper-mapped queries.
[0065] *
[0066] *@param <t>the RowMapper-declared result type
[0067] * /
[0068] interface MappedQuerySpec <t>{
[0069] / / ...
[0070] / **
[0071] If it exists, retrieve the value of the first row and first column of the result, wrap it in an Optional, and return it.
[0072] /
[0073] default Optional <t>first() {
[0074] try(Stream <t>stream = stream()) {
[0075] return stream.findFirst();
[0076] }
[0077] }
[0078] }
[0079] }
[0080] In DefaultJdbcClient, locate the IndexedParamMappedQuerySpec and NamedParamMappedQuerySpec classes and implement the first() method for each. This part modifies the interface implementation, thereby adding the defined first() method to the JDBC standard interface (JdbcClient.MappedQuerySpec interface).
[0081] The first() method implemented by the IndexedParamMappedQuerySpec class:
[0082] @Override
[0083] public Optional <t>first() {
[0084] T result =classicOps.execute(sql, (PreparedStatementCallback <t>)ps -> {
[0085] ps.setMaxRows(1);
[0086] new ArgumentPreparedStatementSetter(indexedParams.toArray()).setValues(ps);
[0087] try(ResultSet rs =ps.executeQuery()) {
[0088] returnrs.next() ? this.rowMapper.mapRow(rs, 0) : null;
[0089] }
[0090] });
[0091] returnOptional.ofNullable(result);
[0092] }
[0093] The code for the first() method implemented by the NamedParamMappedQuerySpec class is as follows:
[0094] @Override
[0095] public Optional <t>first() {
[0096] T result =namedParamOps.execute(sql, namedParamSource, ps -> {
[0097] ps.setMaxRows(1);
[0098] try(ResultSet rs =ps.executeQuery()) {
[0099] returnrs.next() ? this.rowMapper.mapRow(rs, 0) : null;
[0100] }
[0101] });
[0102] returnOptional.ofNullable(result);
[0103] }
[0104] The implementations of the `first()` method in the `IndexedParamMappedQuerySpec` and `NamedParamMappedQuerySpec` classes are largely similar. This explanation will focus on the `first()` method implemented in the `IndexedParamMappedQuerySpec` class. The specific steps are as follows:
[0105] 1. Customize the execution of query SQL by using the execute method of the JdbcOperations class object provided by Spring;
[0106] The actual SQL query is performed using the `execute` method provided by Spring. The query results are obtained by calling the `execute` method.
[0107] For example, to query the first place in a certain ranking, the general syntax is `Select * FROM xxxx order by xxx LIMIT 1`. However, this syntax varies across different databases. For instance, SQL Server uses `select top 1* from xxxx order by xxx`. To mask these SQL differences, some existing technologies retain only the query syntax while removing the restrictive syntax. For example, it can be written as `select * from xxxx order by xxx`, and then the result set `list` can be obtained in Java. The first data can be retrieved using `list.get(0)`. However, this would transmit all the data to the Java layer, increasing network transmission and Java memory overhead. Therefore, this solution uses the JDBC `setMaxRows(1)` method to query SQL without restrictive syntax, such as `select * from xxxx order by xxx`, but sets it to retrieve only one data at a time and closes the connection immediately after retrieving the data. This allows the use of a common SQL syntax without increasing network and memory overhead to retrieve the first sorted data.
[0108] 2. Construct an anonymous implementation of PreparedStatementCallback as the second parameter of the execute method;
[0109] It's important to note that the second parameter is a callback interface, primarily used for setting parameters in the SQL query. The interface is named `PreparedStatementCallback`. Before the SQL is executed, after creating the `PreparedStatement` object, this is the only method of this interface called with the `PreparedStatement` object as the parameter. Then, the parameters can be set based on the obtained `PreparedStatement` object.
[0110] 3. Construct an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism.
[0111] Specifically, the process of constructing the anonymous implementation of PreparedStatementCallback through a two-layer guarantee mechanism is as follows: Figure 2 As shown.
[0112] S201: By calling the setMaxRows method of the PreparedStatement class object ps, the amount of data returned by the database driver is limited so that the maximum number of rows returned by the database driver is 1.
[0113] The setMaxRows method of the PreparedStatement class object ps is a standard JDBC API that is compatible with most database drivers and has better cross-database compatibility compared to SQL-level LIMIT / TOP.
[0114] If `ps.setMaxRows(1)` is called, the dataset will be retrieved in multiple batches when the SQL returns the dataset, with one record retrieved in each batch. Simultaneously, the application layer is also limited to retrieving only one record at a time. For example, it checks if the result set contains data; if it does, only one record is retrieved; otherwise, null is returned and the connection is closed.
[0115] S202: Control the number of rows in the result set during the result set processing stage of the database application layer.
[0116] S203: Bind SQL query parameters under a two-layer protection mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set.
[0117] Specifically, under the two-tiered protection mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set, the process of binding SQL query parameters is as follows: Figure 3 As shown.
[0118] S301: Under the two-layer guarantee mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set, the anonymous implementation of PreparedStatementCallback is used as the callback interface.
[0119] S302: Create an ArgumentPreparedStatementSette class object through the callback interface.
[0120] S303: Bind SQL query parameters using an ArgumentPreparedStatementSette class object.
[0121] Specifically, creating an ArgumentPreparedStatementSetter object is used to bind parameters. For example, in SQL syntax like Select * from xxxx where xxx = ?, which requires parameter binding, the ArgumentPreparedStatementSetter object binds the passed-in parameter array to the SQL in order.
[0122] S204: Perform an SQL query using the bound SQL query parameters to determine whether an SQL query result is obtained, thereby completing the process of constructing an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism.
[0123] S102: In the anonymous implementation of PreparedStatementCallback, if there are SQL query results, map the data corresponding to the SQL query results into an object.
[0124] In S102, under the anonymous implementation of PreparedStatementCallback, if there are SQL query results, the data corresponding to the SQL query results is mapped into objects through the ColumnMapRowMapper mapping tool.
[0125] In the anonymous implementation of PreparedStatementCallback, if no SQL query result exists, a null value is returned.
[0126] S103: Package the object using a preset packaging method.
[0127] In S103, objects can be wrapped using the Optional wrapper class provided by Java. The Optional wrapper class is Optional.ofNullable(result).
[0128] It should be noted that the preset wrapping methods include, but are not limited to, the Optional wrapper class.
[0129] Highlights of this technical solution:
[0130] 1. It is fully implemented based on the JDBC standard interface, without relying on any database-specific syntax, and is compatible with all databases;
[0131] 2. Maintain clean and consistent code; no need to write adaptation logic for different databases.
[0132] 3. While ensuring functional reliability, the amount of network data transmitted and memory usage are minimized to the greatest extent possible;
[0133] 4. Follow the Fluent API design and retain the ability to chain calls;
[0134] 5. Elegant implementation with minimal modifications: Leveraging Java 8's default method feature, new methods are added to interfaces, and all existing implementation classes automatically acquire the new functionality. However, the implementation of these methods is optimized by overriding them in the default implementation. This design ensures 100% backward compatibility while avoiding large-scale framework modifications, embodying the best practice of the "open / closed principle."
[0135] The beneficial effects of this application's embodiments are as follows: By employing a two-layer protection mechanism to limit the amount of data returned at the database driver level and controlling the number of rows in the result set during the database application layer result set processing stage, issues arise where some drivers, such as the Statement.setMaxRows driver, fail to take effect. This two-layer protection mechanism, by controlling the number of rows in the result set during the database application layer result set processing stage to obtain the first row of data in the result set, reduces network transmission, improves performance, and ensures cross-database compatibility. This, in turn, enhances the system's stability and compatibility during SQL queries using JdbcClient.
[0136] Based on the above embodiments Figure 1 The disclosed method for data processing in database queries also includes a corresponding data processing system for database queries, such as... Figure 4 As shown, the data processing system for database queries includes:
[0137] Construction unit 401 is used to construct an anonymous implementation of PreparedStatementCallback through a two-layer guarantee mechanism; wherein, the two-layer guarantee mechanism is a two-layer guarantee mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set at the database application layer result set processing stage;
[0138] Mapping unit 402 is used to map the data corresponding to the SQL query result into an object if there is an SQL query result in the anonymous implementation of PreparedStatementCallback;
[0139] Packaging unit 403 is used to package an object using a preset packaging method.
[0140] Furthermore, building unit 401 includes:
[0141] The limiting module is used to limit the amount of data returned by the database driver by calling the setMaxRows method of the PreparedStatement class object ps, so that the maximum number of rows returned by the database driver is 1.
[0142] The control module is used to control the number of rows in the result set during the result set processing stage of the database application layer.
[0143] The binding module is used to bind SQL query parameters under a two-layer protection mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set;
[0144] The query judgment module is used to perform SQL queries based on the bound SQL query parameters to determine whether SQL query results are obtained, thereby completing the process of building an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism.
[0145] Furthermore, the binding modules include:
[0146] The defined submodule is used as a callback interface through an anonymous implementation of PreparedStatementCallback, under a two-layer guarantee mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set;
[0147] Create a submodule to create ArgumentPreparedStatementSette class objects via a callback interface;
[0148] The binding submodule is used to bind SQL query parameters through ArgumentPreparedStatementSette class objects.
[0149] Furthermore, mapping unit 402 is specifically used, under the anonymous implementation of PreparedStatementCallback, to map the data corresponding to the SQL query result into an object through the ColumnMapRowMapper mapping tool if an SQL query result exists.
[0150] Furthermore, data processing systems for database queries also include:
[0151] The return value is used in the anonymous implementation of PreparedStatementCallback to return an empty value if no SQL query result exists.
[0152] Furthermore, the wrapper unit 403 is specifically used to wrap objects using the Optional wrapper class.
[0153] The beneficial effects of this application's embodiments are as follows: By employing a two-layer protection mechanism to limit the amount of data returned at the database driver level and controlling the number of rows in the result set during the database application layer result set processing stage, issues arise where some drivers, such as the Statement.setMaxRows driver, fail to take effect. This two-layer protection mechanism, by controlling the number of rows in the result set during the database application layer result set processing stage to obtain the first row of data in the result set, reduces network transmission, improves performance, and ensures cross-database compatibility. This, in turn, enhances the system's stability and compatibility during SQL queries using JdbcClient.
[0154] This application embodiment also provides a storage medium, the storage medium including stored instructions, wherein, when the instructions are executed, the device where the storage medium is located is controlled to perform the data processing method for database query as described above.
[0155] This application also provides an electronic device, the structural schematic diagram of which is shown below. Figure 5 As shown, it specifically includes a memory 501 and one or more instructions 502, wherein one or more instructions 502 are stored in the memory 501 and are configured to be executed by one or more processors 503 to perform the above-described data processing method for database query.
[0156] For the foregoing method embodiments, in order to simplify the description, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0157] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system-type embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0158] The steps in the methods of the various embodiments of this application can be adjusted, combined, or deleted according to actual needs.
[0159] Finally, it should be noted that in this paper, relational terms such as first and second are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations.
[0160] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0161] The above description is only a preferred embodiment of this application. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of this application, and these improvements and modifications should also be considered within the scope of protection of this application.< / t> < / t> < / t> < / t> < / t> < / t> < / t>
Claims
1. A data processing method for database queries, characterized in that, The method includes: An anonymous implementation of PreparedStatementCallback is constructed through a two-layer guarantee mechanism; wherein, the two-layer guarantee mechanism is a two-layer guarantee mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set during the result set processing stage at the database application layer; In the anonymous implementation of PreparedStatementCallback, if an SQL query result exists, the data corresponding to the SQL query result is mapped to an object; The object is packaged using a preset packaging method; The anonymous implementation of PreparedStatementCallback constructed through a two-layer protection mechanism includes: By calling the setMaxRows method of the PreparedStatement class object ps, the amount of data returned by the database driver is limited so that the maximum number of rows returned by the database driver is 1. Control the number of rows in the result set during the result set processing stage at the database application layer; Under the two-layer guarantee mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set, SQL query parameters are bound; By performing an SQL query using the bound SQL query parameters, it is determined whether an SQL query result is obtained, thus completing the process of constructing an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism.
2. The method according to claim 1, characterized in that, Under the two-layer protection mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set, the SQL query parameters are bound, including: Under the dual-layer guarantee mechanism of limiting the amount of data returned at the database driver level and controlling the number of rows in the result set, the anonymous implementation of PreparedStatementCallback serves as the callback interface. An ArgumentPreparedStatementSette class object is created through the callback interface; The SQL query parameters are bound using the ArgumentPreparedStatementSette class object.
3. The method according to claim 1, characterized in that, Under the anonymous implementation of PreparedStatementCallback, if an SQL query result exists, the data corresponding to the SQL query result is mapped to an object, including: In the anonymous implementation of PreparedStatementCallback, if there are SQL query results, the data corresponding to the SQL query results is mapped into objects using the ColumnMapRowMapper mapping tool.
4. The method according to claim 1, characterized in that, Also includes: In the anonymous implementation of PreparedStatementCallback, if no SQL query result exists, a null value is returned.
5. The method according to claim 1, characterized in that, The packaging of the object using a preset packaging method includes: The object is wrapped using the Optional wrapper class.
6. A data processing system for database queries, characterized in that, The system includes: The construction unit is used to build an anonymous implementation of PreparedStatementCallback through a two-layer guarantee mechanism; wherein, the two-layer guarantee mechanism is a two-layer guarantee mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set during the result set processing stage at the database application layer. The mapping unit is used to map the data corresponding to the SQL query result into an object if an SQL query result exists under the anonymous implementation of PreparedStatementCallback; A packaging unit is used to package the object using a preset packaging method; The building unit includes: a limiting module, used to limit the amount of data returned by the database driver layer by calling the setMaxRows method of the PreparedStatement class object ps, so that the maximum number of rows returned by the database driver layer is 1; The control module is used to control the number of rows in the result set during the result set processing stage of the database application layer. The binding module is used to bind SQL query parameters under a two-layer protection mechanism that limits the amount of data returned at the database driver level and controls the number of rows in the result set; The query judgment module is used to perform SQL queries based on the bound SQL query parameters to determine whether SQL query results are obtained, thereby completing the process of building an anonymous implementation of PreparedStatementCallback through a two-layer protection mechanism.
7. A storage medium, characterized in that, The storage medium includes stored instructions, wherein, when the instructions are executed, the device in which the storage medium resides executes the data processing method for database query as described in any one of claims 1 to 5.
8. An electronic device, characterized in that, It includes a memory, and one or more instructions, wherein one or more instructions are stored in the memory and configured to be executed by one or more processors for the data processing method for database queries as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Query limiting method and device of application query database
CN116737694A
Processing system and method for united query of heterogeneous data
CN117493429A