简体   繁体   English

如何在java中将名称存储在数据库中

[英]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.我有一个电子表格,其中有多个列,例如“房主姓名”、“地址”、“价格”等。所有列都有 12 个值,涉及 12 个个人,每个人都有他们的地址和其他关于他们财产的详细信息。

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 .而不是数组,我会将电子表格读入类的实例(对象)中,这样每个类代表电子表格中的一行,然后将这些实例放入ArrayList然后您应该能够“搜索” ArrayList

The object oriented way to handle this is to create a Java object with the 12 column names.处理此问题的面向对象方法是创建一个具有 12 个列名的 Java 对象。 Since you only gave us 3 column names, I created this Java objecvt with the 3 names.由于您只给了我们 3 个列名,因此我使用 3 个名称创建了这个 Java 对象。

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.您现在可以创建 HomeOwner 实例列表,并按价格或任何其他列名称搜索列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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