Correlation of queries and database tables that use reflection to handle the same data for multiple table structures

Source: Internet
Author: User
Tags one table

A recent project that requires population data to be queried, but the population data is distributed across the different street tables, first the data table structure is unified, each table begins with a street name, and the other names are the same

The fields in each table are also consolidated in the previous

Abstract out a dictionary table

Link the street number to the first letter of the street name, because the query is using the street number, so that the name of the street table can be spelled out according to the street markings (more than one per population-related table, so it needs to be unified); In the query process, the query to the structure to return a list, (different tables in DAO of course for different classes Ah, return to judge which kind of), and then use reflection field[] fields = List.get (i). Getdeclareddields () to obtain specific properties. Spell out the JSON file to return to the foreground.

This does not count, a lot of information need to relate to other tables, such as community information, community information needs to be based on street information to detect, but not in the same table, so reflected back, according to the results of street information, and then related to other tables for community information, the beginning of the total error, originally I design the corresponding forms, The Java class of database results, stating that the information related to the community before, and the street in the back, then reflected back to traverse the property, the first to traverse the community information, rather than the street, can not be based on the streets to find the specific information of the Community table, community-related information is not and meaningful.

At the same time, when the SQL statement is spelled in the database, it is found that it is necessary to add single quotation marks when adding parameters directly in the statement instead of parameter data.

In addition, = is not the same as in

Report:

Use of the table there,

Population basic information table jiedao1peopleinfo; field name, gender, in order to facilitate return I went to the community, I added the street number field, community-related information 1

Community Table: Community Name, number

Association tables: Community-related information 1, number of community tables

Dictionary table: Street number, street initials

For convenience, I normalized all the table names, searching through street numbers to find the first letter of the street, so that the population tables, community tables, and related tables of the relevant streets could be found.

Return the contents of the population information, then I need to return to the front desk name, gender, street, community, so I also need to follow the street number to find the corresponding table, locate the association table of the street, according to the relevant information given by the foreground, find the Community table number, and then according to the number, find the community name.

If the foreground does not give the parameters, I need to fetch data from multiple streets, so I can relate hundreds of tables, I create a new table directly, unify the basic information of population into one table, plug in directly

INSERT INTO Table_c

SELECT * FROM Table_b

Union

SELECT * FROM Table_a

Start can also, but later there is a problem, that the population table has date data, the original input when the wrong, the format is not, resulting in can not insert, the hundreds of thousands of data I can not see a bar, I just put the data into the use, the method is simple, the asterisk for the specific field column name.

I pass the street number exists to determine whether the foreground input parameters are comprehensive, through such a table, for parameter input uncertainty problem solved

Correlation of queries and database tables that use reflection to handle the same data for multiple table structures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.