CN113722325A - Method and device for detecting table information in database, computer equipment and storage medium - Google Patents

Method and device for detecting table information in database, computer equipment and storage medium Download PDF

Info

Publication number
CN113722325A
CN113722325A CN202111014952.5A CN202111014952A CN113722325A CN 113722325 A CN113722325 A CN 113722325A CN 202111014952 A CN202111014952 A CN 202111014952A CN 113722325 A CN113722325 A CN 113722325A
Authority
CN
China
Prior art keywords
information
database
target
data table
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111014952.5A
Other languages
Chinese (zh)
Inventor
黄恒
程强
万月亮
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Ruian Technology Co Ltd
Original Assignee
Beijing Ruian Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Ruian Technology Co Ltd filed Critical Beijing Ruian Technology Co Ltd
Priority to CN202111014952.5A priority Critical patent/CN113722325A/en
Publication of CN113722325A publication Critical patent/CN113722325A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/252Integrating or interfacing systems involving database management systems between a Database Management System and a front-end application
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the invention discloses a method and a device for detecting table information in a database, computer equipment and a storage medium. Wherein, the method comprises the following steps: inputting the obtained target attribute parameter information of the target database into a pre-constructed information detection component, wherein the information detection component performs connectivity test on the target database by combining the attribute parameter information, and detects table information of a data table in the target database when the connectivity test result is determined to be connected. Compared with the mode of respectively setting detection components for different databases to perform information detection in the prior art, the method effectively saves the information detection time of the databases on the premise of ensuring the accuracy of the detected information, thereby improving the detection efficiency of the data table information in the databases and further ensuring the efficient execution of the whole service performance.

Description

Method and device for detecting table information in database, computer equipment and storage medium
Technical Field
The embodiment of the invention relates to the technical field of data processing, in particular to a method and a device for detecting table information in a database, computer equipment and a storage medium.
Background
Databases (databases) are warehouses that organize, store, and manage data according to data structures, and as information technology and markets develop, databases also evolve into more and more types, and various Database management systems or platforms of different forms for data storage and management, such as oracle databases, mysql databases, postgresql databases, DmDB databases, Gbase databases, etc., which are common at present, also appear.
In practical applications, there is often a need to obtain data information from a database, or to store calculated or determined data in the database. Generally, in order to ensure that data to be stored can be better compatible with a database, it is often necessary to know relevant characteristics of a data table in the database, such as characteristics of a table structure of the data table and data quality of the data table, and the information can be realized by detecting table information of the database, so that data processing can be performed based on a detection result before the data is stored in the data table of the database, and the data to be stored after processing is more fit with characteristics of the data table in the database.
The existing mode for detecting the data table in the database usually needs to set a matched detection mode for different database systems, so that the detection of the data table information can not be effectively realized in the scene of diversified presentation of the database systems, and the efficient execution of the whole service performance is influenced.
Disclosure of Invention
The embodiment of the invention provides a method and a device for detecting table information in a database, computer equipment and a storage medium, which aim to realize the purpose that a user can quickly detect the table information of a data table in a target database.
In a first aspect, an embodiment of the present invention provides a method for detecting table information in a database, including:
acquiring target attribute parameter information of a target database;
performing connectivity test on the target database based on a pre-constructed information detection component in combination with the attribute parameter information;
and when the connectivity test result is determined to be connected, detecting the table information of the data table in the target database.
In a second aspect, an embodiment of the present invention provides an apparatus for detecting table information in a database, including:
the parameter information acquisition module is used for acquiring target attribute parameter information of a target database;
the testing module is used for carrying out connectivity test on the target database based on the pre-constructed information detection component and the attribute parameter information;
and the table information detection module is used for detecting the table information of the data table in the target database when the connectivity test result is determined to be connected.
In a third aspect, an embodiment of the present invention provides a computer device, including:
one or more processors for executing a program to perform,
a storage device for storing one or more programs,
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for detecting table information in a database according to the embodiment of the present invention.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a table information detection method in a database according to an embodiment of the present invention.
According to the technical scheme of the embodiment of the invention, the obtained target attribute parameter information of the target database is input into a pre-constructed information detection component, the information detection component is combined with the attribute parameter information to carry out connectivity test on the target database, and when the connectivity test result is determined to be connected, the table information of the data table in the target database is detected. According to the technical scheme, the mode of integrating the corresponding information of various types of databases into the common detection component (namely the information detection component) is adopted, and compared with the mode of respectively setting the detection components for information detection on different databases in the prior art, the information detection time of the databases is effectively saved on the premise of ensuring the accuracy of the detected information, so that the detection efficiency of the data table information in the databases is improved, and the efficient execution of the whole service performance is ensured.
Drawings
Fig. 1 is a flowchart of a table information detection method in a database according to an embodiment of the present invention;
fig. 2 is a flowchart of a table information detection method in a database according to a second embodiment of the present invention;
fig. 3 is a flowchart illustrating an implementation of table information detection in the method for detecting table information in a database according to a second embodiment of the present invention;
fig. 4 is a block diagram of a table information detection apparatus in a database according to a third embodiment of the present invention;
fig. 5 is a schematic structural diagram of a computer device according to a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some of the structures related to the present invention are shown in the drawings, not all of the structures.
Before discussing exemplary embodiments in more detail, it should be noted that some exemplary embodiments are described as processes or methods depicted as flowcharts. Although a flowchart may describe the steps as a sequential process, many of the steps can be performed in parallel, concurrently or simultaneously. In addition, the order of the steps may be rearranged. The process may be terminated when its operations are completed, but may have additional steps not included in the figure. The processes may correspond to methods, functions, procedures, subroutines, and the like.
Example one
Fig. 1 is a flowchart of a method for detecting table information in a database according to an embodiment of the present invention, where this embodiment is applicable to a case where table information in a database is detected before data is stored in the database, and this method may be executed by an apparatus for detecting table information in a database according to an embodiment of the present invention, where this apparatus may be implemented by software and/or hardware, and this apparatus may be configured in a computer device.
As shown in fig. 1, the method for detecting table information in a database specifically includes the following steps:
s110, acquiring target attribute parameter information of a target database.
In the present embodiment, the target database is a warehouse for organizing, storing and managing data according to a data structure, and is an organized, sharable, and uniformly managed collection of a large amount of data stored in a computer for a long time. It should be noted that, according to different types of databases, the databases may be classified into a relational database, a non-relational database, and a distributed database. The embodiment of the invention is suitable for the relational database. For example, the target Database may be an Oracle Database (Oracle), a MySQL Database (MySQL ), a PostgreSQL Database (PostgreSQL ), a dreams Database (Dameng Database, Dm), and a Gbase Database (Gbase Database, Gbase).
In this embodiment, the target attribute parameter information may include a database type, a database Internet Protocol (IP) address, a database port, a database user name, a database password, a database name, and a data table name.
For example, in the target attribute parameter information of the target database obtained in this step, the database type may be a type of a relational database such as oracle, mysql, postgresql, Dm, and Gbase. The database IP address may be a local host (localhost) or 127.0.0.1, the oracle port may be 1521, the mysql port may be 3306, the postgresql port may be 5432, the DmDB port may be 5236, and the Gbase port may be 5258, the user name may be root, the password may be 123456, and the database name may be "test" embodiments of the invention do not limit the database type, the database IP address, the database port, the database user name, the database password, and the database name.
It should be noted that, before using the method for detecting table information in a database provided by the embodiment of the present invention, a user may provide target attribute parameter information of a target database to the execution subject by way of information editing.
And S120, performing connectivity test on the target database based on the pre-constructed information detection component and the target attribute parameter information.
In the embodiment of the present invention, the information detection component may include a string splicing function and a database connection function. The character string splicing function and the database connection function of the corresponding database can be integrated by judging the type of the database. The character string splicing function can splice the target attribute parameters according to the format of the corresponding connection character string of the target database to form the connection character string of the target database; the database connection function can perform connectivity test on the corresponding target database based on the connection character strings spliced by the character string splicing function.
In an embodiment of the present invention, the connectivity test may refer to a test of connectivity of the information detection component and the target database.
Illustratively, the information detection component judges the database type in the target attribute parameter information, calls a character string splicing function of the corresponding database type, splices the target attribute parameters according to the format of the connection character string of the target database to obtain a spliced connection character string, calls a corresponding database connection function, uses the spliced connection character string as the input of the database connection function, and finally tests connectivity between the database connection function and the target database.
And S130, when the connectivity test result is determined to be connected, detecting the table information of the data table in the target database.
In this embodiment, when it is determined that the connectivity test result is connectivity, it may be understood that the information detection component establishes a connection with the target database, and the information detection component may perform a detection operation on the target database. It should be noted that the information detection component may further include a database detection function, and the database detection function may also integrate the database detection functions of the corresponding databases by determining the types of the databases. The database detection function has a function of detecting the table structure of the data table in the target database and the data in the table.
In this embodiment, the table information may be information such as a table structure and/or data condition in the table. The detection may be understood as querying, examining or exploring the information of the data table in the target database.
Illustratively, first, a corresponding database connection function in the information detection component and the target database are called for connectivity test by judging the type of the database in the target attribute parameter information, if the database connection function returns a connection object, the connectivity test result is determined to be connected, then, the database detection function in the information detection component is called, the returned connection object is used as the input of the corresponding database detection function, and finally, the database detection function queries the table structure of the data table in the database and the data in the table.
According to the technical scheme of the embodiment of the invention, the obtained target attribute parameter information of the target database is input into a pre-constructed information detection component, the information detection component is combined with the attribute parameter information to carry out connectivity test on the target database, and when the connectivity test result is determined to be connected, the table information of the data table in the target database is detected. According to the technical scheme, the mode of integrating the corresponding information of various types of databases into the common detection component (namely the information detection component) is adopted, and compared with the mode of respectively setting the detection components for information detection on different databases in the prior art, the information detection time of the databases is effectively saved on the premise of ensuring the accuracy of the detected information, so that the detection efficiency of the data table information in the databases is improved, and the efficient execution of the whole service performance is ensured.
Specifically, the optional embodiment of the present invention may specifically express the target attribute parameter information of the target database as: the method comprises the following steps of (1) database type, database name, database IP address, database port, database user name, database password and data table name; the information detection component may be specifically expressed as: and the information items to be filled correspond to the attribute parameter information of the database.
It will be appreciated that each type of database has a different fill format, and that each type of database has a fill format that contains information items to be filled. The attribute parameter information of each type of database can be correspondingly filled into the information items to be filled in the filling format of each type of database, so that the positioning character strings of each database can be formed. The locator string may be a connection string of a computer programming language (java) DataBase connection (JDBC), and is used to identify a location of the target DataBase and tell the JDBC which DataBase is connected to the locator string. JDBC is a suite of computer Programming Language (java) Application Programming Interfaces (APIs) for executing Structured Query Language (SQL) statements, which allow a user to access any form of table information, particularly information stored in a relational database. JDBC realizes communication with various databases, can provide uniform access interfaces for various relational databases, and adapts to SQL statements to complete operations of querying, updating, deleting and the like of data in the databases. JDBC provides a benchmark by which more advanced tools and interfaces can be built to enable database developers to write database applications. Specifically, a user can establish a database connection through JDBC, create a statement to execute SQL, process the execution results, and release resources.
It should be noted that the information detection component may have the following functions: the filling format of the corresponding type database can be found according to the database type in the attribute parameter information of each type of database as a judgment condition, so that the positioning string of the corresponding type database can be formed. Illustratively, if the database type is oracle database, the filling format of the oracle database may be "jdbc: oracle: thin: @ item to be filled 1: item to be filled 2: item to be filled 3", the user may fill the database IP address "127.0.0.1" in the attribute parameter of the database into the item to be filled 1, the database port "1521" in the attribute parameter of the database into the item to be filled 2, the database name "oracle database 1" in the attribute parameter of the database into the item to be filled 3, and the positioning string of the oracle database may be "jdbc: oracle: thin: @ 127.0.1: 1521: oracle database 1". If the database type is mysql database, the filling format of the mysql database may be "jdbc: mysql// item to be filled 1: item to be filled 2:/item to be filled 3", the item to be filled 1 may be filled with the database IP address "localhost" in the attribute parameter of the database input by the user, the item to be filled 2 is filled with the database port "3306" in the attribute parameter of the database, the item to be filled 3 is filled with the database name "mydb" in the attribute parameter of the database, and the locating string of the mysql database may be "jdbc: mysql:// localhost: 3306/mydb".
In an optional embodiment of this embodiment, the information detection component may obtain a corresponding filling format according to attribute parameter information of each type of database input by a user, and may fill the attribute parameter information in an information item to be filled in the corresponding filling format to form a location string corresponding to the database. Therefore, the method has the effect of dynamically forming the positioning character string of the target database according to the attribute parameter information of the target database input by the user.
Example two
Fig. 2 is a flowchart of a table information detection method in a database according to a second embodiment of the present invention, and the present embodiment is optimized based on the above embodiment. In the embodiment of the present invention, a connectivity test may be performed on the target database by combining the information detection component based on the pre-configuration with the target attribute parameter information, and specifically, the connectivity test is optimized as follows: constructing a target bit string based on the target attribute parameter information; calling a given connectivity test function, and carrying out connectivity test on the target database and the information detection component by combining the target bit string; and when the function return value is the set mark, determining that the connectivity test result of the connectivity test is connectivity.
Meanwhile, in the second embodiment, table information of the data table in the target database may also be detected, which is specifically optimized as follows: acquiring a target detection function corresponding to the target database when a connectivity test result is connected, wherein the target detection function is assembled in the information detection component; and calling the target detection function from the information detection component through a matched function interface, and detecting the table information of the data table in the target database by adopting the target detection function.
As shown in fig. 2, the method for detecting table information in a database according to the second embodiment of the present invention specifically includes the following steps:
s210, acquiring target attribute parameter information of the target database.
S220, forming a target bit string based on the target attribute parameter information.
In the above operation, the information detection component may obtain a corresponding filling format according to the database type in the target attribute parameter information of the target database obtained by performing S210, and may fill the target attribute parameter information, such as the database IP address, the database port, the database name, and other information, in the information item to be filled in the corresponding filling format to form the target bitstring corresponding to the target database.
And S230, calling a given connectivity test function, and performing connectivity test on the target database and the information detection component by combining the target bit string.
In the above operation, the connectivity test function may be a getConnection () method in a DriverManager class in a computer programming language (java) API of JDBC. Where DriveManager is the computer programming language (java) API of JDBC, the DriveManager is used to load JDBC drivers and create connections to databases. Therein, the getConnection () method in DriverManager is used to establish a connection with the database and return a connection (connection) object representing the connection.
For example, the connectivity test function may be a Connection ═ drivermanage.getconnection (target bit string, database username, database password). It should be noted that, in step S230, according to the database user name and the database password in the target attribute parameter information of the target database obtained by executing step S210 and the target bitstring obtained by executing step S220, the target bitstring is used as a parameter of the connectivity test function, and then the connectivity test function is called to perform connectivity test on the database located by the target bitstring.
S240, when the function return value is the setting mark, determining that the connectivity test result of the connectivity test is connected.
In the above operation, the function return value may return an information prompt, or may be a return connection (connection) object. The connection object is returned by getConnection () method in DriverManager.
In the above operation, the setting flag may be a connection object.
Exemplarily, when the function return value returns the information prompt of 'no database user name or database password' or 'network failure, connection overtime' and the like, determining that the connectivity test result of the connectivity test is failure; when the function return value returns a connection (connection) object representing a connection, the result of the connectivity test is determined to be connected. Among these, there are a series of methods in the Connection interface corresponding to the Connection object, such as the getMetadata () method, which is used to return the database metadata object of the database metadata representing the metadata of the database. Wherein the databaseMetaData is a computer programming language (java) API of JDBC.
And S250, when the connectivity test result is determined to be connected, acquiring a target detection function of the target database when the connectivity test result is connected, wherein the target detection function is assembled in the information detection assembly.
It can be understood that, by calling the connectivity test function to perform connectivity test with the target database, when the connectivity test function returns a connection (connection) object, it is determined that the connectivity test function is connected, and at this time, the connection object returned by the connectivity test function is received by obtaining the target detection function in the information detection component corresponding to the target database.
S260, the target detection function is called from the information detection component through a matched function interface, and the target detection function is adopted to detect the table information of the data table in the target database.
It should be noted that the corresponding filling format may be found through the database type of the attribute parameter information of the target database, and a matched function interface may also be found. Specifically, the type of the database in the attribute parameter information is judged first, a corresponding filling format is found, items to be filled in the corresponding filling format are filled, a target bit string is formed, meanwhile, a connectivity test function is called by combining a database user name and a database password of the attribute parameter information, and when the connectivity test result is connected, a target detection function of the target database can be obtained through a matched function interface, the matched function interface receives a connectivity test result returned by the connectivity test function as a connected connection object, and transmits the received connection object to the obtained target detection function, at this time, the target detection function can detect a table structure of a data table in the corresponding connected database or data in the table.
According to the embodiment of the invention, a target bit string is obtained according to the target attribute parameter information, a given connectivity test function is called, the target database is subjected to connectivity test by combining the target bit string, and when the function return value is a set mark, the connectivity test result of the connectivity test is determined to be connected. Enabling a program of a user to realize the communication with the target database by inputting the target attribute parameter information of the target database so as to provide a more effective method for communicating the database; when the detection component is communicated with the target database, the corresponding target detection function of the target database is obtained from the information detection component through the matched function interface, and the table information of the data table in the target database is detected, so that the detection component can detect the table information of the data table in the target database.
It should be noted that, in the second embodiment, the steps S210, S220, S230, and S240 may be implemented to detect connectivity of the target database by the information detection component; executing S210, S220, S230, S240, S250 and S260 in the second embodiment may implement connectivity test of the information detection component on the target database and detection of the target database.
Further, as shown in fig. 3, fig. 3 is a flowchart illustrating an implementation of table information detection in a database table information detection method according to a second embodiment of the present invention, and an alternative embodiment of the present invention detects table information of a data table in a target database by using the target detection function, and further may be optimized as follows:
s2601, obtaining the data table name information of each data table included in the target database through the metadata object of the target database.
In the above operation, the metadata of the target database may be information defined by a database, a data table, and the like. It should be noted that, in this embodiment, when the metadata object is connected according to the connectivity test result of the connectivity test, a getMetadata () method in a Connection (Connection) interface corresponding to a returned Connection (Connection) object obtains a database metadata object of a database metadata data of the target database, obtains data table name information of each data table included in the target database by using a getTables () method corresponding to the database metadata object, and returns the data table name information by using a tableNameResultSet object of ResultSet. Wherein ResultSet is the computer programming language (java) API of JDBC.
S2602, determining the table structure information of the data table to be detected in the target database according to the name information of the data table.
It can be understood that, through the obtained name information of the data table, the name of the data table to be detected is searched in the name information of the data table, and if the name of the data table to be detected can be found in the name information of the data table, the table structure information of the data table to be detected can be inquired through the name of the data table to be detected. The table structure information may include field name, field type, field length, and other information. It should be noted that the data table name of the data table to be detected can be obtained from executing S210.
S2603, determining the data attribute information of the data table to be detected by sampling the data of the data table to be detected.
It can be understood that data in the data table to be detected may be extracted, the number of data extractions is not limited in this embodiment, and the extracted data may be analyzed, so as to obtain data attribute information of the data table to be detected.
Illustratively, 1000 pieces of data of a data table to be detected are extracted, specific values of the data are filled according to requirements of corresponding fields in a table structure, and the data are analyzed according to field names, so that data attribute information of the data table to be detected can be determined. For example, the data that occurs the most often per field.
In an optional embodiment of the present invention, the target detection function obtains the name information of the data tables included in the target database by obtaining the metadata object of the target database, determines the table structure information of the data table to be detected in the target database according to the table name information, and determines the data attribute information of the data table to be detected by sampling the data of the data table to be detected. The problem that a user frequently inquires the table structure information of various types of databases and inquires the data attribute information of the data tables of the various types of databases at a low speed is solved, and the effect that the user can perform more effective database detection according to the information detection assembly is achieved.
Specifically, in an optional embodiment of the present invention, the table structure information of the to-be-detected data table in the target database is determined according to the name information of the data table, and specifically, the table structure information may be optimized as follows:
a1, determining the list of table names of the data table included in the target database through the data table name information.
In this embodiment, the target detection function obtains the metadata databaseMetaData object of the target database, obtains the data table name information of each data table included in the target database by using a getTables () method corresponding to the databaseMetaData object, returns the data table name information by using the tableNameResultSet object of ResultSet, and may traverse the tableNameResultSet by using a loop statement to obtain the table name list of the data table of the target database.
b1, if the table name of the data table to be detected exists in the table name list, querying the table structure information of the data table to be detected through a set first query statement, where the table structure information includes: english name of field, type of field, length of field.
In the above operation, the table name of the to-be-detected data table is obtained by user input, specifically, the table name of the to-be-detected data table is obtained from the data table name in the target attribute parameter information of the target database. If the table name of the data table to be detected is not in the table name list, prompting that 'no table exists' information, otherwise, if the table name of the data table to be detected is in the table name list, querying the table structure information of the data table to be detected through a set first query statement, wherein the first query statement can obtain the table structure information of the data table to be detected through a getColumns () method corresponding to a database MetaData object, returns through a Result fieldResultSet object, and can obtain the table structure information through traversal of a loop statement to the fieldResultSet. Where Result is the computer programming language (java) API of JDBC.
The table structure information includes: field english name, field type, and field length. The field english name may be name 1(field1), the field type may be integer (int), single precision floating point (float), data type (char) capable of accommodating a single character, timestamp type (timestamp), and the like, and the field length may be 10, 16, and 7. As shown in table 1.
TABLE 1 Table Structure information of data tables in the database
English name of field Type of field Length of field
field1 int 10
field2 char 16
field3 timestamp 7
......
In an optional embodiment of the present invention, a table name list of the data table included in the target database is determined according to the data table name information, and whether the table name of the data table to be detected exists in the table name list is determined, and if the table name of the data table to be detected exists in the table name list, the table structure information of the data table to be detected is queried according to a set first query statement. The method for inquiring the table structure information of the data table to be detected by the information detection component is realized, so that the more effective method for inquiring the table structure information by a user is provided.
Specifically, in the optional embodiment of the present invention, the data attribute information of the to-be-detected data table is determined by sampling the data of the to-be-detected data table, and specifically, the optional embodiment of the present invention may be optimized as follows:
a2, performing traversal operation on the data table to be detected through a set second query statement, and obtaining the sampling data in the data table to be detected.
In the above operation, specifically, the set second query statement may be a set SQL query statement, and the traversing operation is performed on the data table to be detected to obtain the sample data in the data table to be detected. The number of the sample data in the data table to be detected may be obtained by a preset value, for example, 2000 pieces of sample data.
It can be understood that each piece of data content in the sample data in the data table to be detected may be a value corresponding to a field type corresponding to the english name of the field, for example, the name 1(field1), and the corresponding field type is integer (int), so that the corresponding data value may be 139, 23, 14, 3, and the like, and the embodiment of the present invention does not limit the data values of the name 1(field1) and the corresponding integer (int); name 2(field2), the corresponding field type is a data type (char) that can accommodate a single character, and the corresponding data value can be zhang san, li si, wang dong and zhang san, etc., the embodiment of the present invention does not limit the data value of the corresponding data type (char) that can accommodate a single character for name 2(field 2); name 3(field3), and if the corresponding field type is integer (int), the corresponding data value may be 9, null, 37, and the like, and the embodiment of the present invention does not limit the data value of name 3(field3) and the corresponding integer (int); name 4(field4), and the corresponding field type is timestamp type (timestamp), the corresponding data value may be 2021-08-02, 2021-07-12, and 2021-06-14, etc., and the embodiment of the present invention does not limit the data value of name 4(field4) and the corresponding timestamp type (timestamp). As shown in table 2.
TABLE 2 data of data tables in the database
field1 field2 field3 field4 ......
139 Zhang San 9 2021-08-02
23 Li Si 2021-07-12
14 Wang Dongdong 37 2021-07-12
3 Zhang San 37 2021-06-14
......
b2, determining data attribute information of the data table to be detected through a given information statistical strategy, wherein the data attribute information comprises: and the highest occurrence frequency element information, the minimum length value, the maximum length value and the cell filling rate of each field in the data table to be detected.
In the above operation, specifically, the sample data in the data table to be detected is traversed through a loop statement, and data attribute information is determined for the data table to be detected through a given information statistical strategy, where the data attribute information includes: and the highest occurrence frequency element information, the minimum length value, the maximum length value and the cell filling rate of each field in the data table to be detected. Wherein the highest occurrence frequency element information may be a data value having a largest number of occurrences in the field. The minimum length value may be the minimum length of all data values in the field. The maximum length value may be the maximum length of all data values in the field. The cell fill rate may be a percentage of the number of cells in the field that contain data values to a number of preset cells. The data attribute information may also include a maximum value and a minimum value in the data table to be detected, where the maximum value may be a maximum value of all data values in the field, and the minimum value may be a minimum value of all data values in the field.
Illustratively, the name 1(field1), the corresponding field type is integer (int), the corresponding data value may be 139, 23, 14, 3, etc., and the data attribute information in the field name 1(field1) in the data table to be detected may be: the highest appearance frequency elements may be 3, 14, 23, the minimum length value may be 1, the maximum length value may be 3, the cell fill rate may be 100%, the maximum value may be 139, and the minimum value may be 3; name 2(field2), the corresponding field type is a data type (char) capable of accommodating a single character, the corresponding data value may be zhang, li si, wang dong and zhang, etc., and the data attribute information in field name 2(field2) in the data table to be detected may be: the maximum occurrence frequency element can be Zhang three, the minimum length value can be 2, the maximum length value can be 3, the cell filling rate can be 100%, the maximum value is null, and the minimum value is null; name 3(field3), the corresponding field type is integer (int), and the corresponding data value may be 9, null, 37, etc., and the data attribute information in field name 3(field3) in the data table to be detected may be: the highest appearance frequency element may be 37, the minimum length value may be 1, the maximum length value may be 2, the cell filling rate may be 75%, the maximum value may be 37, and the minimum value may be 9; name 4(field4), the corresponding field type is timestamp type (timestamp), the corresponding data value may be 2021-08-02, 2021-07-12, 2021-06-14, etc., and the data attribute information in field name 4(field4) in the data table to be detected may be: the highest frequency of occurrence element may be 2021-07-12, the minimum length value may be 7, the maximum length value may be 7, the cell fill rate may be 100%, the maximum value may be 2021-08-02, and the minimum value may be 2021-06-14. As shown in table 3.
TABLE 3 data attribute information for data tables in the database
Figure BDA0003240054740000191
In the embodiment of the invention, the set second query statement is used for performing traversal operation on the data table to be detected to obtain the sampling data in the data table to be detected, and the data attribute of the data table to be detected is determined through a given information statistical strategy, so that the information detection component can query the data attribute of the data table to be detected, and the data attribute information of the data table of the database can be more effectively queried by a user.
It should be noted that a1 and b1 in the second embodiment are implemented to realize the detection of the table structure information of the data table in the target database by the information detection component. The second embodiment of a1, b1, a2 and b2 can also be implemented to realize that the information detection component detects table structure information of data tables in a target database and determines data attributes. Of course, the precondition is that the connectivity test is performed between the information detection component and the target database, and the connectivity test result between the information detection component and the target database is communication.
EXAMPLE III
Fig. 4 is a block diagram of a table information detection apparatus in a database according to a third embodiment of the present invention, where the apparatus is capable of executing a table information detection method in a database according to any embodiment of the present invention, and has functional modules and beneficial effects corresponding to the execution method. The device is configured in computer equipment to realize the method for detecting the table information in the database in the embodiment of the invention. As shown in fig. 4, the apparatus includes: a parameter information acquisition module 410, a test module 420, and a table information detection module 430.
The parameter information acquiring module 410 is configured to acquire target attribute parameter information of a target database;
a testing module 420, configured to perform connectivity testing on the target database based on a pre-constructed information detection component in combination with the attribute parameter information;
and a table information detection module 430, configured to detect table information of a data table in the target database when it is determined that the connectivity test result is connectivity.
According to the technical scheme of the embodiment of the invention, the obtained target attribute parameter information of the target database is input into a pre-constructed information detection component, the information detection component is combined with the attribute parameter information to carry out connectivity test on the target database, and when the connectivity test result is determined to be connected, the table information of the data table in the target database is detected. According to the technical scheme, the mode of integrating the corresponding information of various types of databases into the common detection component (namely the information detection component) is adopted, and compared with the mode of respectively setting the detection components for information detection on different databases in the prior art, the information detection time of the databases is effectively saved on the premise of ensuring the accuracy of the detected information, so that the detection efficiency of the data table information in the databases is improved, and the efficient execution of the whole service performance is ensured.
In the above apparatus, optionally, the target attribute parameter information of the target database includes: the method comprises the following steps of (1) database type, database name, database IP address, database port, database user name, database password and data table name;
the information detection assembly includes: and the information items to be filled correspond to the attribute parameter information of the database.
In the above apparatus, optionally, the testing module 420 is specifically configured to:
constructing a target bit string based on the target attribute parameter information;
calling a given connectivity test function, and carrying out connectivity test on the target database and the information detection component by combining the target bit string;
and when the function return value is the set mark, determining that the connectivity test result of the connectivity test is connectivity.
In the above apparatus, optionally, the table information detecting module 430 includes a function obtaining unit and a detecting unit:
the function obtaining unit is used for obtaining a target detection function of the target database when a connectivity test result is connected, and the target detection function is assembled in the information detection component;
the detection unit is used for calling the target detection function from the information detection component through a matched function interface and detecting the table information of the data table in the target database by adopting the target detection function.
In the above apparatus, optionally, the detection unit includes: a table name acquisition subunit, a table structure determination subunit, and a data attribute determination subunit:
the table name obtaining subunit is configured to obtain, through the metadata object of the target database, data table name information of each data table included in the target database;
the table structure determining subunit is configured to determine, according to the data table name information, table structure information of a data table to be detected in the target database;
and the data attribute determining subunit is configured to determine the data attribute information of the data table to be detected by sampling the data of the data table to be detected.
In the above apparatus, optionally, the table structure determining subunit is specifically configured to:
the determining the table structure information of the data table to be detected in the target database according to the name information of the data table comprises the following steps:
determining a table name list of a data table included in the target database according to the name information of the data table;
if the table name of the data table to be detected exists in the table name list, inquiring the table structure information of the data table to be detected through a set first inquiry statement, wherein the table structure information comprises: english name of field, type of field, length of field.
In the above apparatus, optionally, the data attribute determining subunit is specifically configured to:
traversing the data table to be detected through a set second query statement to obtain sampling data in the data table to be detected;
determining data attribute information of the data table to be detected through a given information statistical strategy, wherein the data attribute information comprises: and the highest occurrence frequency element information, the minimum length value, the maximum length value and the cell filling rate of each field in the data table to be detected.
The product can execute the table information detection method in the database provided by the embodiment of the invention, and has corresponding functional modules and beneficial effects of the execution method.
Practice four
The fourth embodiment of the invention provides computer equipment. Fig. 5 is a schematic structural diagram of a computer device according to a fourth embodiment of the present invention. As shown in fig. 5, the present embodiment provides a computer apparatus, which may include: a processor and a storage device. At least one instruction is stored in the storage device, and the instruction is executed by the processor, so that the computer device executes the method for detecting the table information in the database according to the embodiment of the method.
Referring to fig. 5, the computer device may specifically include: processor 510, storage 520, input 530, and output 540; the number of the processors 510 in the computer device may be one or more, and one processor 510 is taken as an example in fig. 5; the number of the storage devices 520 in the computer apparatus may be one or more, and one storage device 520 is taken as an example in fig. 5. The processor 510, the storage 520, the input 530 and the output 540 of the computer apparatus may be connected by a bus or other means, and fig. 5 illustrates an example of a connection by a bus.
In particular, in an embodiment, when the processor 510 executes one or more programs stored in the storage device 520, the following operations may be implemented: acquiring target attribute parameter information of a target database; performing connectivity test on the target database based on a pre-constructed information detection component in combination with the target attribute parameter information; and when the connectivity test result is determined to be connected, detecting the table information of the data table in the target database.
The device, the computer device and the storage medium for detecting the table information in the database provided by the above embodiments can execute the method for detecting the table information in the database provided by any embodiment of the present invention, and have corresponding functional modules and beneficial effects for executing the method. Technical details that are not described in detail in the above embodiments may be referred to a method for detecting table information in a database according to any embodiment of the present invention.
EXAMPLE five
An embodiment five of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements a method for detecting table information in a database according to any embodiment of the present invention, where the method includes: acquiring target attribute parameter information of a target database; performing connectivity test on the target database based on a pre-constructed information detection component in combination with the target attribute parameter information; and when the connectivity test result is determined to be connected, detecting the table information of the data table in the target database.
Computer storage media for embodiments of the invention may employ any combination of one or more computer-readable media. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the 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 the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (10)

1. A method for detecting table information in a database is characterized by comprising the following steps:
acquiring target attribute parameter information of a target database;
performing connectivity test on the target database based on a pre-constructed information detection component in combination with the target attribute parameter information;
and when the connectivity test result is determined to be connected, detecting the table information of the data table in the target database.
2. The method of claim 1, wherein the target attribute parameter information of the target database comprises: the method comprises the following steps of (1) database type, database name, database IP address, database port, database user name, database password and data table name;
the information detection assembly includes: and the information items to be filled correspond to the attribute parameter information of the database.
3. The method according to any one of claims 1 or 2, wherein performing connectivity testing on the target database based on a pre-constructed information detection component in combination with the target attribute parameter information comprises:
constructing a target bit string based on the target attribute parameter information;
calling a given connectivity test function, and carrying out connectivity test on the target database and the information detection component by combining the target bit string;
and when the function return value is the set mark, determining that the connectivity test result of the connectivity test is connectivity.
4. The method of claim 1, wherein the detecting table information of the data table in the target database comprises:
acquiring a target detection function of the target database when a connectivity test result is connected, wherein the target detection function is assembled in the information detection component;
and calling the target detection function from the information detection component through a matched function interface, and detecting the table information of the data table in the target database by adopting the target detection function.
5. The method of claim 4, wherein the detecting table information of the data table in the target database by using the target detection function comprises:
acquiring data table name information of each data table included in the target database through a metadata object of the target database;
determining the table structure information of the data table to be detected in the target database according to the name information of the data table;
and determining the data attribute information of the data table to be detected by sampling the data of the data table to be detected.
6. The method according to claim 5, wherein the determining table structure information of the data table to be detected in the target database according to the name information of the data table comprises:
determining a table name list of a data table included in the target database according to the name information of the data table;
if the table name of the data table to be detected exists in the table name list, inquiring the table structure information of the data table to be detected through a set first inquiry statement, wherein the table structure information comprises: english name of field, type of field, length of field.
7. The method according to claim 5, wherein the determining the data attribute information of the data table to be detected by sampling the data of the data table to be detected comprises:
traversing the data table to be detected through a set second query statement to obtain sampling data in the data table to be detected;
determining data attribute information of the data table to be detected through a given information statistical strategy, wherein the data attribute information comprises: and the highest occurrence frequency element information, the minimum length value, the maximum length value and the cell filling rate of each field in the data table to be detected.
8. An apparatus for detecting table information in a database, comprising:
the parameter information acquisition module is used for acquiring target attribute parameter information of a target database;
the testing module is used for carrying out connectivity test on the target database based on the pre-constructed information detection component and the attribute parameter information;
and the table information detection module is used for detecting the table information of the data table in the target database when the connectivity test result is determined to be connected.
9. A computer device, comprising:
one or more processors;
storage means for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of table information detection in a database as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a method of table information detection in a database according to any one of claims 1 to 7.
CN202111014952.5A 2021-08-31 2021-08-31 Method and device for detecting table information in database, computer equipment and storage medium Pending CN113722325A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111014952.5A CN113722325A (en) 2021-08-31 2021-08-31 Method and device for detecting table information in database, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111014952.5A CN113722325A (en) 2021-08-31 2021-08-31 Method and device for detecting table information in database, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113722325A true CN113722325A (en) 2021-11-30

Family

ID=78680092

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111014952.5A Pending CN113722325A (en) 2021-08-31 2021-08-31 Method and device for detecting table information in database, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113722325A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116467178A (en) * 2023-03-21 2023-07-21 北京飞轮数据科技有限公司 Database detection method, apparatus, electronic device and computer readable medium
CN117389996A (en) * 2023-12-11 2024-01-12 深圳万物安全科技有限公司 Database optimization suggestion generation method, terminal equipment and storage medium
CN117950591A (en) * 2024-01-18 2024-04-30 北京微控工业网关技术有限公司 Gateway storage management method and device, electronic equipment and storage medium
CN118568423A (en) * 2024-08-02 2024-08-30 朗坤智慧科技股份有限公司 Method and system for intelligently realizing data cleaning by using AI model

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160306827A1 (en) * 2015-04-15 2016-10-20 International Business Machines Corporation Synchronizing data rules and corresponding metadata to implement data governance
CN108959564A (en) * 2018-07-04 2018-12-07 玖富金科控股集团有限责任公司 Data warehouse metadata management method, readable storage medium storing program for executing and computer equipment
CN109614426A (en) * 2018-10-26 2019-04-12 深圳壹账通智能科技有限公司 Switching method, device and electronic equipment between multiple database
CN110855526A (en) * 2019-11-20 2020-02-28 北京百分点信息科技有限公司 Method and device for detecting data source connection, storage medium and electronic equipment
CN112181936A (en) * 2019-07-03 2021-01-05 北京京东尚科信息技术有限公司 Database detection method and device
CN112559523A (en) * 2020-12-11 2021-03-26 北京锐安科技有限公司 Data detection method and device, electronic equipment and storage medium
CN113010527A (en) * 2021-04-22 2021-06-22 苏州创腾软件有限公司 Processing method and device for detection data, computer equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160306827A1 (en) * 2015-04-15 2016-10-20 International Business Machines Corporation Synchronizing data rules and corresponding metadata to implement data governance
CN108959564A (en) * 2018-07-04 2018-12-07 玖富金科控股集团有限责任公司 Data warehouse metadata management method, readable storage medium storing program for executing and computer equipment
CN109614426A (en) * 2018-10-26 2019-04-12 深圳壹账通智能科技有限公司 Switching method, device and electronic equipment between multiple database
CN112181936A (en) * 2019-07-03 2021-01-05 北京京东尚科信息技术有限公司 Database detection method and device
CN110855526A (en) * 2019-11-20 2020-02-28 北京百分点信息科技有限公司 Method and device for detecting data source connection, storage medium and electronic equipment
CN112559523A (en) * 2020-12-11 2021-03-26 北京锐安科技有限公司 Data detection method and device, electronic equipment and storage medium
CN113010527A (en) * 2021-04-22 2021-06-22 苏州创腾软件有限公司 Processing method and device for detection data, computer equipment and storage medium

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116467178A (en) * 2023-03-21 2023-07-21 北京飞轮数据科技有限公司 Database detection method, apparatus, electronic device and computer readable medium
CN116467178B (en) * 2023-03-21 2024-02-20 北京飞轮数据科技有限公司 Database detection method, apparatus, electronic device and computer readable medium
CN117389996A (en) * 2023-12-11 2024-01-12 深圳万物安全科技有限公司 Database optimization suggestion generation method, terminal equipment and storage medium
CN117389996B (en) * 2023-12-11 2024-03-29 深圳万物安全科技有限公司 Database optimization suggestion generation method, terminal equipment and storage medium
CN117950591A (en) * 2024-01-18 2024-04-30 北京微控工业网关技术有限公司 Gateway storage management method and device, electronic equipment and storage medium
CN118568423A (en) * 2024-08-02 2024-08-30 朗坤智慧科技股份有限公司 Method and system for intelligently realizing data cleaning by using AI model
CN118568423B (en) * 2024-08-02 2024-10-18 朗坤智慧科技股份有限公司 Method and system for intelligently realizing data cleaning by using AI model

Similar Documents

Publication Publication Date Title
CN113722325A (en) Method and device for detecting table information in database, computer equipment and storage medium
CN110990447B (en) Data exploration method, device, equipment and storage medium
US10565201B2 (en) Query processing management in a database management system
US10120916B2 (en) In-querying data cleansing with semantic standardization
CN106407303A (en) Data storage method and apparatus, and data query method and apparatus
CN110704476A (en) Data processing method, device, equipment and storage medium
US11709831B2 (en) Cost-based query optimization for array fields in database systems
US12079181B2 (en) Efficient indexing for querying arrays in databases
CA3017523C (en) Technologies for auto discover and connect to a rest interface
US11126656B2 (en) Formatting semi-structured data in a database
CN111125213A (en) Data acquisition method, device and system
CN110008462B (en) Command sequence detection method and command sequence processing method
CN117130932A (en) SQL static detection method and device for big data platform
CN117407414A (en) Method, device, equipment and medium for processing structured query statement
CN109101595B (en) Information query method, device, equipment and computer readable storage medium
CN108959454B (en) Prompting clause specifying method, device, equipment and storage medium
US8548980B2 (en) Accelerating queries based on exact knowledge of specific rows satisfying local conditions
CN110580170B (en) Method and device for identifying software performance risk
CN112487025A (en) Data query method and device, electronic equipment and storage medium
CN111797095A (en) Index construction method and JSON data query method
CN114860658A (en) Data acquisition method and device, electronic equipment and storage medium
CN112835905B (en) Array type column indexing method, device, equipment and storage medium
CN114116764A (en) Index query method, device, medium and electronic equipment based on syntax tree
CN114281842A (en) Method and device for sub-table query of database
CN110633430B (en) Event discovery method, apparatus, device, and computer-readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination