JDBC-based database file uploading method, device, equipment and storage medium
Through the database file upload method based on JDBC, the problem of low efficiency of database data export is solved, flexible data processing and efficient concurrent processing are realized, and the processing efficiency and quality of database data export are improved.
Patent Information
- Application Number
- CN202410687715.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-05-30
AI Technical Summary
Existing database data export technology cannot be separated from the application system and database, resulting in low processing efficiency and unable to meet the requirements of rapid business growth and quality improvement.
Adopt the JDBC-based database file upload method, call the export interface through the database table upload command to read the target attribute file configuration information, start the multi-threaded export task, and use JDBC's pre-compilation mechanism and automatic paging execution method to read data from the database. After preprocessing, upload to the file server.
It achieves flexible, configurable and customizable data processing, decouples file export tasks and application systems, and improves data processing efficiency and concurrent processing capabilities.
Smart Images

Figure CN118277472B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a JDBC-based database file uploading method, device, equipment and storage medium. Background Art
[0002] Database table export mainly exports the contents of the data table in the database into a text file, and then uploads it to the file storage system, so that the system using the data can retrieve and use it. Most of the existing database table exports use the database's own export commands, manual export using graphical management tools, application coding, etc., which are mainly divided into four stages: data preparation, data reading, data processing, and export to files. The first two methods do not support data processing. Due to the expansion of corporate production and business activities, the amount of data has continued to rise, and the demand for large-scale data interaction between systems has also continued to increase. Database table export and upload is the key task of large-scale data interaction between systems.
[0003] However, the existing database data export has the following problems: the export command that comes with the database is usually for the entire table or even the entire database, and lacks fine-grained control such as defining the data range in the table and defining the data columns that need to be exported. The existing export tools can only export according to the original data value, and cannot convert or process the data format according to business needs. The exported files need to be processed again, which doubles the workload. Due to human subjectivity, different people lack a unified standard for the use of export tools, resulting in inconsistent formats and encodings of exported files, causing production accidents. When exporting through application coding, each export task needs to be re-coded and developed, resulting in a lot of repetitive work, which is not conducive to improving work efficiency. Therefore, the prior art for database data export cannot be separated from the application system and database, resulting in poor configuration flexibility, and a large amount of data relies on manual processing, resulting in low processing efficiency. Summary of the invention
[0004] The main purpose of this application is to provide a database file upload method, device, equipment and storage medium based on JDBC, aiming to solve the technical problems in the prior art that database data export cannot be separated from the application system and database, a large amount of data relies on manual processing, resulting in low processing efficiency and unable to meet the requirements of rapid business growth and quality improvement.
[0005] To achieve the above purpose, the present application provides a database file upload method based on JDBC, and the database file upload method based on JDBC includes the following steps:
[0006] Based on the database table upload instruction, call the export interface to read the target property file configuration information;
[0007] Based on the target property file configuration information and the preset asynchronous batch export mechanism, a multi-threaded export task is started, and based on the JDBC pre-compilation mechanism and the preset automatic paging execution mode, the database data to be exported is read from the database;
[0008] Preprocessing the database data to be exported based on a preprocessing function to obtain a text file in a target data format;
[0009] Upload the text file to a file server.
[0010] Optionally, before the step of calling the export interface to read the target property file configuration information based on the database table upload instruction, the step further includes:
[0011] Get file header information configuration information, file content information configuration information, export thread pool configuration information and retry configuration information;
[0012] The target attribute file configuration information is constructed according to the file header information configuration information, the file content information configuration information, the export thread pool configuration information and the retry configuration information.
[0013] Optionally, the step of starting a multi-threaded export task based on the target property file configuration information and a preset asynchronous batch export mechanism, and reading the database data to be exported from the database based on a JDBC pre-compilation mechanism and a preset automatic paging execution mode includes:
[0014] Determine the size of the database file to be uploaded based on the file header information configuration information and the file content information configuration information;
[0015] Determine the number of export tasks based on the retry configuration information;
[0016] Determine the parameters of the thread to be started according to the size of the database file to be uploaded and the export thread pool configuration information;
[0017] Based on the JDBC pre-compilation mechanism, the number of export tasks, the parameters of the threads to be started, the preset asynchronous batch export mechanism and the preset automatic paging execution mode, a multi-threaded export task is started to obtain the database data to be exported.
[0018] Optionally, before the step of preprocessing the database data to be exported based on a preprocessing function to obtain a text file in a target data format, the step further includes:
[0019] Determine whether there are any exceptions in the export task execution process;
[0020] If there is an exception in the export task execution process, the export information and the exception information are recorded, and it is determined whether the failure result needs to be sent according to the export information and the exception information;
[0021] If a failure result needs to be sent, send the result to Kafka.
[0022] Optionally, before the step of recording the export information and the exception information if there is an exception in the export task execution process, and judging whether to send the failure result according to the export information and the exception information, the step further includes:
[0023] If there is no abnormality in the execution process of the export task, determine whether it is necessary to pre-process the database data to be exported;
[0024] If so, the to-be-exported database data is preprocessed based on a preprocessing function to obtain a text file in a target data format.
[0025] Optionally, if there is an exception in the execution process of the export task, the step of recording the export information and the exception information, and judging whether to send a failure result according to the export information and the exception information includes:
[0026] If there is an exception in the export task execution process, the task execution step is determined according to the timestamp, and the exception information is generated according to the exception code corresponding to the task execution step, the export task details, the number of code lines where the exception occurs, and the error details;
[0027] Generate export information according to the configuration number corresponding to the export task, the input parameters of the calling method, and the task execution steps;
[0028] Determine whether a failure result needs to be sent based on the exception information and the export information.
[0029] Optionally, after the step of uploading the text file to the file server, the method further includes:
[0030] Regularly exporting records of task execution failure from the database, and using the failed steps recorded in the records as the starting steps of the retry operation;
[0031] The export interface is called to read the configuration parameters in the record, and the input parameters of the calling method recorded in the record are overwritten, and the file upload process is executed according to the starting step.
[0032] In addition, to achieve the above purpose, the present application also provides a JDBC-based database file uploading device, the JDBC-based database file uploading device comprising:
[0033] Configuration reading module, used to call export interface to read target attribute file configuration information based on database table upload instruction;
[0034] A data export module is used to start a multi-threaded export task based on the target property file configuration information and a preset asynchronous batch export mechanism, and read the database data to be exported from the database based on the JDBC pre-compilation mechanism and a preset automatic paging execution mode;
[0035] A file processing module, used for preprocessing the database data to be exported based on a preprocessing function to obtain a text file in a target data format;
[0036] The file uploading module is used to upload the database file to be uploaded to the file server.
[0037] In addition, to achieve the above-mentioned purpose, the present application also proposes a JDBC-based database file upload device, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the JDBC-based database file upload method as described above.
[0038] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by the processor, the steps of the JDBC-based database file upload method as described above are implemented.
[0039] One or more technical solutions proposed in this application have at least the following technical effects:
[0040] This application calls the export interface based on the database table upload instruction to read the target attribute file configuration information; based on the target attribute file configuration information and the preset asynchronous batch export mechanism, the multi-threaded export task is started, and the database data to be exported is read from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution method; the database data to be exported is pre-processed based on the pre-processing function to obtain a text file in the target data format; and the text file is uploaded to the file server. This application establishes a database table export mechanism that is flexible, configurable, and customizable for data processing, introduces SQL input and export field definitions, decouples the file export task from the application system, and improves the file export concurrent processing capability through a multi-threaded processing mechanism, thereby improving data processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0042] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0043] Figure 1 A flowchart of the first embodiment of the JDBC-based database file upload method provided by the present application;
[0044] Figure 2 A schematic diagram of the file export and upload process provided for the second embodiment of the JDBC-based database file upload method of the present application;
[0045] Figure 3 This is a schematic diagram of the module structure of a JDBC-based database file upload device according to an embodiment of the present application;
[0046] Figure 4 This is a schematic diagram of the device structure of the hardware operating environment involved in the JDBC-based database file upload method in the embodiment of the present application.
[0047] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0048] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0049] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0050] The main solution of the embodiment of the present application is: based on the database table upload instruction, the export interface is called to read the target property file configuration information; based on the target property file configuration information and the preset asynchronous batch export mechanism, a multi-threaded export task is started, and based on the JDBC pre-compilation mechanism and the preset automatic paging execution method, the database data to be exported is read from the database; based on the pre-processing function, the database data to be exported is pre-processed to obtain a text file in the target data format; and the text file is uploaded to the file server.
[0051] In this embodiment, for ease of description, the following description is made with the computing service device as the execution entity.
[0052] Since the data export of the database in the existing technology cannot be separated from the application system and the database, a large amount of data relies on manual processing, resulting in low processing efficiency and failure to meet the requirements of rapid business growth and quality improvement.
[0053] The present application provides a solution to decouple the file export task from the application system, improve the file export concurrent processing capability through a multi-threaded processing mechanism, and improve data processing efficiency.
[0054] From the above embodiments, it can be seen that the present application reads the target attribute file configuration information by calling the export interface based on the database table upload instruction; starts the multi-threaded export task based on the target attribute file configuration information and the preset asynchronous batch export mechanism, and reads the database data to be exported from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution method; pre-processes the database data to be exported based on the pre-processing function to obtain a text file in the target data format; and uploads the text file to the file server. The present application establishes a database table export mechanism that is flexible, configurable, and customizable for data processing, introduces SQL input and export field definitions, decouples the file export task from the application system, improves the file export concurrent processing capability through a multi-threaded processing mechanism, and improves data processing efficiency.
[0055] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, including a device of a database file upload system based on JDBC, etc. The following takes a computer as an example to illustrate this embodiment and the following embodiments.
[0056] Based on this, the embodiment of the present application provides a database file upload method based on JDBC, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the JDBC-based database file upload method of the present application.
[0057] In this embodiment, the JDBC-based database file uploading method includes steps S10 to S40:
[0058] Step S10: Call the export interface to read the target attribute file configuration information based on the database table upload instruction.
[0059] It should be noted that the database table upload instruction can be an instruction triggered by the developer or a pre-set instruction, wherein the target property file configuration information can be based on the pre-defined Properties file configuration information. The Properties file configuration information can include file header information configuration and file content information configuration. By reading the target property file configuration information, the data format corresponding to the database data to be exported and the required data content can be determined.
[0060] In a feasible implementation, before step S10, it also includes: obtaining file header information configuration information, file content information configuration information, export thread pool configuration information and retry configuration information; and forming the target attribute file configuration information according to the file header information configuration information, the file content information configuration information, the export thread pool configuration information and the retry configuration information.
[0061] It should be noted that the file header information configuration information may include a switch for determining whether file header information is required, an SQL statement for generating a file header, a list of field names output from an SQL result set to the file header, a separator for file header fields, and other information; the file content information configuration information may include an SQL statement for generating file content, a list of field names output from an SQL result set to the file content, a separator for file content fields, field content modifiers, automatic data paging size, and other information.
[0062] It should be understood that the exported thread pool configuration information may include information such as the number of core threads, the maximum number of threads, the thread queue size, etc., and the retry configuration information may include information such as the retry switch, the number of retries, the retry task trigger frequency, the number of retry loading tasks, etc.
[0063] It is understandable that the present application determines data export rules by pre-defining Properties file configuration, and constructs Properties configuration file through data export rules, thereby obtaining target property file configuration information.
[0064] Step S20, starting a multi-threaded export task based on the target property file configuration information and a preset asynchronous batch export mechanism, and reading the database data to be exported from the database based on a JDBC pre-compilation mechanism and a preset automatic paging execution mode.
[0065] It should be noted that the preset asynchronous batch export mechanism is an asynchronous non-blocking mechanism designed and introduced in advance on the server side. The asynchronous non-blocking mechanism can mean that multiple export tasks can be started at the same time, and each task is processed by an independent thread pool by reading different export configurations respectively. The export tasks that need to be started at the same time can be determined through the target property file configuration information and the asynchronous batch export mechanism, and different export tasks can be processed through independent thread pools.
[0066] It is understandable that the precompilation mechanism of JDBC can refer to the underlying warehousing technology using the PrepareStatement with a precompilation mechanism in JDBC. Compared with using Mybatis as an intermediate proxy layer or using Statement that requires repeated compilation, this method only needs to modify the paging parameters in the precompiled SQL to execute SQL, thereby greatly improving the query efficiency of exported data and saving about 80% of the query time.
[0067] It should be understood that the preset automatic paging execution mode can be a pre-set automatic paging reading and parsing data table outbound execution mode, in which the incoming SQL is executed in a paging manner to avoid loading the entire data table data into the memory at one time and causing memory overflow. The paging size can be custom configured, and multi-threading will be enabled in the export task. The task of pulling different paging data will be submitted to its own independent thread pool to achieve multi-threaded concurrent processing, which greatly improves the execution efficiency of the export task.
[0068] Step S30, preprocessing the database data to be exported based on a preprocessing function to obtain a text file in a target data format.
[0069] It should be noted that the preprocessing function can be a processing function that is rewritten according to the data format pre-set by the developer. The server of this application provides a preprocessing interface for the user to implement. After executing SQL to obtain the result set from the database, the server will first call this method to process the result set, and then export the processed results to the file, thereby realizing customized processing of data table export.
[0070] In a specific implementation, the present application rewrites the data format of the database data to be exported through a preprocessing function to obtain a text file in the target data format.
[0071] Step S40: Upload the text file to a file server.
[0072] It should be noted that this application pre-configures the export file upload mechanism. After the export is completed, an export file will be generated locally. You can configure whether to upload it to a specified file server. It supports two upload methods: sftp and http. After uploading, the export file saved locally will be automatically cleared to save disk space.
[0073] This embodiment calls the export interface based on the database table upload instruction to read the target attribute file configuration information; based on the target attribute file configuration information and the preset asynchronous batch export mechanism, the multi-threaded export task is started, and the database data to be exported is read from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution method; the database data to be exported is pre-processed based on the pre-processing function to obtain a text file in the target data format; and the text file is uploaded to the file server. This embodiment establishes a database table export mechanism that is flexible, configurable, and customizable for data processing, introduces SQL input and export field definitions, decouples the file export task from the application system, and improves the file export concurrent processing capability through a multi-threaded processing mechanism, thereby improving data processing efficiency.
[0074] Based on the above Figure 1The first embodiment shown proposes a second embodiment of the database file upload method based on JDBC of the present application; based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as the above-mentioned first embodiment can be referred to the above introduction and will not be repeated later.
[0075] In this embodiment, the step S20 also includes: determining the size of the database file to be uploaded based on the file header information configuration information and the file content information configuration information; determining the number of export tasks based on the retry configuration information; determining the parameters of the thread to be started according to the size of the database file to be uploaded and the export thread pool configuration information; starting a multi-threaded export task based on the JDBC precompilation mechanism, the number of export tasks, the parameters of the thread to be started, the preset asynchronous batch export mechanism and the preset automatic paging execution mode to obtain the database data to be exported.
[0076] It should be noted that the size of the database file to be uploaded is determined based on the file header information configuration information and the file content information configuration information; the number of export tasks is determined based on the retry configuration information; the parameters of the threads to be started are determined according to the size of the database file to be uploaded and the export thread pool configuration information; based on the JDBC precompilation mechanism, the number of export tasks, the parameters of the threads to be started, the preset asynchronous batch export mechanism and the preset automatic paging execution mode, the multi-threaded export task is started to obtain the database data to be exported.
[0077] In the specific implementation, the present application can also achieve more flexible configuration by setting up a memory increase mechanism, a concurrency increase mechanism, a custom segmented upload mechanism, a fault protection mechanism, a link tracking mechanism and a performance evaluation mechanism, so as to meet the data processing of multiple scenarios, wherein the memory increase mechanism can be through increasing the memory, a larger paging size can be set, or the data table reading method is changed from paging reading to reading the entire table data into the memory at one time, reducing the number of interactions with the database, thereby speeding up the file out of the warehouse. Therefore, the present application scheme is not limited to the preset automatic paging execution method, and the specific mechanism can be pre-customized according to the actual situation. Increase concurrency mechanism: By increasing the number of supported outbound threads and better disk IO, the efficiency of data table outbound can be greatly improved. Custom segmented upload mechanism: If the exported file is too large, the file can be segmented and uploaded according to the configured file size. Fault protection mechanism: Provide a quick and automatic retry mechanism according to the configuration information when a fault occurs during a certain export task. Link tracking mechanism: Provide an overall link tracking mechanism from reading data from the data table to parsing out of the warehouse and uploading. Performance evaluation mechanism: Provide a performance evaluation mechanism from reading data from the data table to parsing out of the warehouse and uploading.
[0078] In this embodiment, before step S30, it also includes: determining whether there is an exception in the export task execution process; if there is an exception in the export task execution process, recording the export information and the exception information, and determining whether it is necessary to send a failure result based on the export information and the exception information; if it is necessary to send a failure result, sending a kafka notification result.
[0079] It should be noted that this application pre-configures the error handling mechanism. When an abnormal situation occurs during the execution of the export task, it will connect to the real-time log monitoring receipt to record the export information and abnormal information. According to the preset configuration result notification mechanism, after the file is exported and uploaded, the server will send the task result to the specified kafka. If it is successful, it will include the file storage address. If it fails, it will provide error information.
[0080] It is understandable that it is necessary to determine whether there is an exception in the execution process of the export task; if there is an exception in the execution process of the export task, the export information and the exception information are recorded, and it is determined whether it is necessary to send a failure result based on the export information and the exception information; if it is necessary to send a failure result, the kafka notification result is sent.
[0081] Furthermore, before the step of recording the export information and the exception information if there is an exception in the execution process of the export task, and judging whether it is necessary to send a failure result based on the export information and the exception information, it also includes: if there is no exception in the execution process of the export task, judging whether it is necessary to preprocess the database data to be exported; if so, preprocessing the database data to be exported based on a preprocessing function to obtain a text file in the target data format.
[0082] It should be noted that if there is no abnormality in the execution process of the export task, it is determined whether the database data to be exported needs to be preprocessed; if preprocessing is required, the database data to be exported is preprocessed based on the preprocessing function to obtain a text file in the target data format.
[0083] Furthermore, if there is an exception in the export task execution process, the export information and the exception information are recorded, and the step of judging whether it is necessary to send a failure result is determined based on the export information and the exception information. The step includes: if there is an exception in the export task execution process, the task execution step is determined according to the timestamp, and the exception information is generated according to the exception code corresponding to the task execution step, the export task details, the number of lines of code where the exception occurs, and the error details; the export information is generated according to the configuration number corresponding to the export task, the input parameters of the calling method, and the task execution step; and whether it is necessary to send a failure result is judged based on the exception information and the export information.
[0084] It should be noted that when an exception occurs during the execution of the export task, the event of the exception will be recorded and a timestamp will be generated. The task execution step will be marked according to the timestamp to determine the task execution step where the exception occurs. The exception code corresponding to the task execution step, the export task details, the number of lines of code where the exception occurs, and the detailed error information will be printed out and connected to the real-time log monitoring receipt. Therefore, if there is an exception in the execution of the export task, the exception information will be generated according to the exception code corresponding to the task execution step, the export task details, the number of lines of code where the exception occurs, and the detailed error information; the export information will be generated according to the configuration number corresponding to the export task, the input parameters of the calling method, and the task execution step; and it will be determined whether a failure result needs to be sent based on the exception information and the export information.
[0085] In the specific implementation, to further explain the application storage processing process, refer to Figure 2 The schematic diagram of the server-side processing warehousing process is shown in the figure, in which this solution establishes a database table export mechanism that is flexible, configurable and customizable for data processing, introduces SQL input and export field definitions, and decouples the file export task from the application system; improves the file export concurrent processing capability through a multi-threaded processing mechanism; implements export retry failure through the export retry strategy configuration function; implements timely notification of the end of the export task through the kafka notification function; and implements the upload of exported files through http, sftp and other methods, realizing a loosely coupled, configurable, highly available and high-performance database table custom export upload component.
[0086] This embodiment calls the export interface based on the database table upload instruction to read the target attribute file configuration information; based on the target attribute file configuration information and the preset asynchronous batch export mechanism, the multi-threaded export task is started, and the database data to be exported is read from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution method; the database data to be exported is pre-processed based on the pre-processing function to obtain a text file in the target data format; and the text file is uploaded to the file server. This embodiment establishes a database table export mechanism that is flexible, configurable, and customizable for data processing, introduces SQL input and export field definitions, decouples the file export task from the application system, and improves the file export concurrent processing capability through a multi-threaded processing mechanism, thereby improving data processing efficiency.
[0087] Based on the first embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those of the above-mentioned first embodiment can be referred to the above introduction and will not be repeated later.
[0088] In this embodiment, step S40 also includes: periodically exporting records of failed task execution from the database, and using the failed steps recorded in the records as the starting steps of the retry operation; calling the export interface to read the configuration parameters in the records, and overwriting the input parameters of the calling method recorded in the records, and executing the file upload process according to the starting step.
[0089] It should be noted that the present application pre-configures a failure retry mechanism, wherein the failure retry mechanism is to periodically pull the record of failed export task execution from the database through the server, and start execution according to the "export", "upload", and "message sending" steps it is in, so as to avoid repeating the successful steps and save time. The export task record saves the configuration number, the input parameters of the method called at that time, the step, the number of retries, and the error message. The retry execution is the same as the normal export process, first reading the configuration parameters, and then overwriting them with the method input parameters saved in the record.
[0090] It should be understood that the records of failed task execution are exported from the database at a regular interval, and the failed steps recorded in the records are used as the starting steps of the retry operation; the export interface is called to read the configuration parameters in the records, and the input parameters of the calling method recorded in the records are overwritten, and the file upload process is executed according to the starting steps.
[0091] In the specific implementation, this application is developed through pre-customization, based on a non-blocking asynchronous framework, and defines export rules through a Properties configuration file. It also supports overwriting of parameters passed in during calls, establishes a mapping relationship between database tables and export files, and allows custom methods to process the original data obtained from the data table, thereby implementing custom data processing before export.
[0092] This embodiment calls the export interface based on the database table upload instruction to read the target attribute file configuration information; based on the target attribute file configuration information and the preset asynchronous batch export mechanism, the multi-threaded export task is started, and the database data to be exported is read from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution method; the database data to be exported is pre-processed based on the pre-processing function to obtain a text file in the target data format; and the text file is uploaded to the file server. This embodiment establishes a database table export mechanism that is flexible, configurable, and customizable for data processing, introduces SQL input and export field definitions, decouples the file export task from the application system, and improves the file export concurrent processing capability through a multi-threaded processing mechanism, thereby improving data processing efficiency.
[0093] This application also provides a database file upload device based on JDBC, please refer to Figure 3 , the JDBC-based database file uploading device includes:
[0094] Configuration reading module 10, used to call export interface to read target attribute file configuration information based on database table upload instruction;
[0095] The data export module 20 is used to start the multi-threaded export task based on the target attribute file configuration information and the preset asynchronous batch export mechanism, and read the database data to be exported from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution mode;
[0096] A file processing module 30, used for preprocessing the database data to be exported based on a preprocessing function to obtain a text file in a target data format;
[0097] The file uploading module 40 is used to upload the database file to be uploaded to the file server.
[0098] Furthermore, the JDBC-based database file upload device also includes a mechanism configuration module, which is used to obtain file header information configuration information, file content information configuration information, export thread pool configuration information and retry configuration information; and to form target attribute file configuration information according to the file header information configuration information, the file content information configuration information, the export thread pool configuration information and the retry configuration information.
[0099] Furthermore, the data export module 20 is also used to determine the size of the database file to be uploaded based on the file header information configuration information and the file content information configuration information; determine the number of export tasks based on the retry configuration information; determine the parameters of the thread to be started according to the size of the database file to be uploaded and the export thread pool configuration information; start the multi-threaded export task based on the JDBC precompilation mechanism, the number of export tasks, the parameters of the thread to be started, the preset asynchronous batch export mechanism and the preset automatic paging execution mode to obtain the database data to be exported.
[0100] Furthermore, the JDBC-based database file upload device also includes an exception judgment module, which is used to judge whether there is an exception in the execution process of the export task; if there is an exception in the execution process of the export task, the export information and the exception information are recorded, and it is judged whether it is necessary to send a failure result based on the export information and the exception information; if a failure result needs to be sent, a kafka notification result is sent.
[0101] Furthermore, the file processing module 30 is also used to determine whether it is necessary to preprocess the database data to be exported if there is no abnormality in the execution process of the export task; if so, preprocess the database data to be exported based on a preprocessing function to obtain a text file in the target data format.
[0102] Furthermore, the exception judgment module is also used to determine the task execution step according to the timestamp if there is an exception in the export task execution process, and generate exception information according to the exception code corresponding to the task execution step, export task details, the number of code lines where the exception occurred, and error details; generate export information according to the configuration number corresponding to the export task, the input parameters of the calling method, and the task execution step; and judge whether it is necessary to send a failure result based on the exception information and the export information.
[0103] Furthermore, the file upload module 40 is also used to periodically export records of failed task execution from the database, and use the failed steps recorded in the records as the starting steps of the retry operation; call the export interface to read the configuration parameters in the records, and overwrite the input parameters of the calling method recorded in the records, and execute the file upload process according to the starting steps.
[0104] The JDBC-based database file upload device provided by the present application adopts the JDBC-based database file upload method in the above embodiment, and can solve the technical problem of JDBC-based database file upload. Compared with the prior art, the beneficial effects of the JDBC-based database file upload device provided by the present application are the same as the beneficial effects of the JDBC-based database file upload method provided by the above embodiment, and other technical features in the JDBC-based database file upload device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0105] The present application provides a JDBC-based database file upload device, which includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the JDBC-based database file upload method in the first embodiment described above.
[0106] Reference below Figure 4 , which shows a schematic diagram of the structure of a JDBC-based database file upload device suitable for implementing the embodiment of the present application. The JDBC-based database file upload device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The JDBC-based database file upload device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0107] like Figure 4 As shown, the JDBC-based database file upload device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the JDBC-based database file upload device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems may be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 may allow the JDBC-based database file upload device to communicate wirelessly or wired with other devices to exchange data. Although the JDBC-based database file upload device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.
[0108] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0109] The JDBC-based database file upload device provided by the present application adopts the JDBC-based database file upload method in the above embodiment, which can solve the technical problem of JDBC-based database file upload. Compared with the prior art, the beneficial effects of the JDBC-based database file upload device provided by the present application are the same as the beneficial effects of the JDBC-based database file upload method provided in the above embodiment, and other technical features in the JDBC-based database file upload device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0110] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0111] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0112] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, the computer-readable program instructions being used to execute the JDBC-based database file uploading method in the above-mentioned embodiment.
[0113] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.
[0114] The computer-readable storage medium may be included in the JDBC-based database file upload device; or may exist independently without being assembled into the JDBC-based database file upload device.
[0115] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by a JDBC-based database file upload device, the JDBC-based database file upload device: when the JDBC-based database file upload device is executed, the JDBC-based database file upload device: calls the export interface based on the database table upload instruction to read the target attribute file configuration information; starts the multi-threaded export task based on the target attribute file configuration information and the preset asynchronous batch export mechanism, and reads the database data to be exported from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution mode; pre-processes the database data to be exported based on the pre-processing function to obtain a text file in the target data format; and uploads the text file to the file server.
[0116] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0117] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0118] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0119] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned JDBC-based database file upload method, and can solve the technical problem of JDBC-based database file upload. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the JDBC-based database file upload method provided by the above-mentioned embodiment, and will not be repeated here.
[0120] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A database file uploading method based on JDBC, characterized in that: The JDBC-based database file uploading method includes: Based on the database table upload instruction, call the export interface to read the target property file configuration information; Based on the target property file configuration information and the preset asynchronous batch export mechanism, a multi-threaded export task is started, and based on the JDBC pre-compilation mechanism and the preset automatic paging execution mode, the database data to be exported is read from the database; Preprocessing the database data to be exported based on a preprocessing function to obtain a text file in a target data format; Uploading the text file to a file server; The steps of starting a multi-threaded export task based on the target property file configuration information and the preset asynchronous batch export mechanism, and reading the database data to be exported from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution mode include: Determine the size of the database file to be uploaded based on the file header information configuration information and the file content information configuration information; Determine the number of export tasks based on the retry configuration information; Determine the parameters of the thread to be started according to the size of the database file to be uploaded and the export thread pool configuration information; Based on the JDBC pre-compilation mechanism, the number of export tasks, the parameters of the threads to be started, the preset asynchronous batch export mechanism and the preset automatic paging execution mode, a multi-threaded export task is started to obtain the database data to be exported; Before the step of preprocessing the database data to be exported based on the preprocessing function to obtain a text file in a target data format, the step further includes: Determine whether there are any exceptions in the export task execution process; If there is no abnormality in the execution process of the export task, determine whether it is necessary to pre-process the database data to be exported; If yes, preprocessing the database data to be exported based on the preprocessing function to obtain a text file in the target data format; If there is an exception in the export task execution process, the task execution step is determined according to the timestamp, and the exception information is generated according to the exception code corresponding to the task execution step, the export task details, the number of code lines where the exception occurs, and the error details; Generate export information according to the configuration number corresponding to the export task, the input parameters of the calling method, and the task execution steps; Determine whether to send a failure result according to the abnormal information and the export information; If a failure result needs to be sent, send the result to Kafka for notification; After the step of uploading the text file to the file server, the method further includes: Regularly exporting records of task execution failure from the database, and using the failed steps recorded in the records as the starting steps of the retry operation; The export interface is called to read the configuration parameters in the record, and the input parameters of the calling method recorded in the record are overwritten, and the file upload process is executed according to the starting step.
2. The method according to claim 1, characterized in that Before the step of calling the export interface to read the target attribute file configuration information based on the database table upload instruction, the method further includes: Get file header information configuration information, file content information configuration information, export thread pool configuration information and retry configuration information; The target attribute file configuration information is constructed according to the file header information configuration information, the file content information configuration information, the export thread pool configuration information and the retry configuration information.
3. A database file uploading device based on JDBC, characterized in that: The device comprises: Configuration reading module, used to call export interface to read target attribute file configuration information based on database table upload instruction; A data export module is used to start a multi-threaded export task based on the target property file configuration information and a preset asynchronous batch export mechanism, and read the database data to be exported from the database based on the JDBC pre-compilation mechanism and a preset automatic paging execution mode; A file processing module, used for preprocessing the database data to be exported based on a preprocessing function to obtain a text file in a target data format; A file upload module, used for uploading the text file to a file server; The steps of starting a multi-threaded export task based on the target property file configuration information and the preset asynchronous batch export mechanism, and reading the database data to be exported from the database based on the JDBC pre-compilation mechanism and the preset automatic paging execution mode include: Determine the size of the database file to be uploaded based on the file header information configuration information and the file content information configuration information; Determine the number of export tasks based on the retry configuration information; Determine the parameters of the thread to be started according to the size of the database file to be uploaded and the export thread pool configuration information; Based on the JDBC pre-compilation mechanism, the number of export tasks, the parameters of the threads to be started, the preset asynchronous batch export mechanism and the preset automatic paging execution mode, a multi-threaded export task is started to obtain the database data to be exported; Before the step of preprocessing the database data to be exported based on the preprocessing function to obtain a text file in a target data format, the step further includes: Determine whether there are any exceptions in the export task execution process; If there is no abnormality in the execution process of the export task, determine whether it is necessary to pre-process the database data to be exported; If yes, preprocessing the database data to be exported based on the preprocessing function to obtain a text file in the target data format; If there is an exception in the export task execution process, the task execution step is determined according to the timestamp, and the exception information is generated according to the exception code corresponding to the task execution step, the export task details, the number of code lines where the exception occurs, and the error details; Generate export information according to the configuration number corresponding to the export task, the input parameters of the calling method, and the task execution steps; Determine whether to send a failure result according to the abnormal information and the export information; If a failure result needs to be sent, send the result to Kafka for notification; After the step of uploading the text file to the file server, the method further includes: Regularly exporting records of task execution failure from the database, and using the failed steps recorded in the records as the starting steps of the retry operation; The export interface is called to read the configuration parameters in the record, and the input parameters of the calling method recorded in the record are overwritten, and the file upload process is executed according to the starting step.
4. A database file upload device based on JDBC, characterized in that: The JDBC-based database file uploading device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the JDBC-based database file uploading method as described in any one of claims 1 or 2.
5. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, the steps of the JDBC-based database file uploading method as described in any one of claims 1 or 2 are implemented.
