简体   繁体   中英

How to store names in a database in java

Hi this is my first time using this because I am confused as to how I should go about this problem.

I have a spreadsheet which has multiple columns such as "house owner names", "Address", "price" etc. All of the columns have 12 values in them relating to 12 individuals each with their address and other such details regarding their property.

I need to create a program where if I enter a certain price range, the program sorts through the spreadsheet and only displays the results that fall within the price range that the user enters.

I first thought of using multiple one-dimensional arrays in parallel, but I am not sure if this is the correct way to do such a thing, also I do not know if it is possible to to search through arrays for specific ranges and then have it display to the console.

In this instance I would say your spreadsheet is acting as your database.
Rather than arrays, I would read the spread sheet into instances (objects) of a class, such that each class represents a row in your spreadsheet, and then put these instances into an ArrayList You should then be able to "search" the ArrayList .

The object oriented way to handle this is to create a Java object with the 12 column names. Since you only gave us 3 column names, I created this Java objecvt with the 3 names.

public class HomeOwner {

    private final String name;
    private final String address;

    private final double price;

    public HomeOwner(String name, String address, double price) {
        this.name = name;
        this.address = address;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }

    public double getPrice() {
        return price;
    }

}

You can now create a List of HomeOwner instances, and search the List by price or any of the other column names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM