我有两个ObservableList <people>,但是我无法合并到另一个ObservableList <people>

时间:2019-05-06 11:33:16

标签: java javafx

我有People对象和两个ObservableList。每个ObservableList中都有值。所有ObservableList都应放在表中。我试图像这样将所有ObservableList收集到第三个ObservableList

 ObservableList<Bemor> main = FXCollections.observableArrayList();
        ObservableList<Bemor> first = func.selectfirst();

        ObservableList<Bemor> second = func.selectsecont();

        main.add((Bemor) first);
        main.add((Bemor) second);

tableview.setItems(main);

func.selectfirst()func.selectsecont()函数,它们返回ObservableList<Bemor> 但返回错误

使用DBFunc进行SQL查询

selectfirst()

        ObservableList<Bemor> first=FXCollections.observableArrayList();
        ConnectDb db =new ConnectDb();
        Connection connection =db.getConnection();
        Statement statement =connection.createStatement();
        String sql="SELECT bemor.fish, bolim.nomi, doktor.fish,bemor.navbat,xizmat.nomi,bemor.id,bolim.id,navbat.id,xizmat.id,doktor.id" +
                " FROM bemor JOIN doktor ON doktor.id=bemor.doktor_id " +
                "JOIN xizmat ON xizmat.id=doktor.xizmat_id " +
                "JOIN bolim ON bolim.id=xizmat.bolim_id " +
                "JOIN navbat ON navbat.doktor_id=doktor.id GROUP BY doktor.id" ;

        ResultSet rs=statement.executeQuery(sql);
        while(rs.next())

        {
            first.add(new Bemor(
                    rs.getString(1),
                    rs.getString(2),
                    rs.getString(3),
                    rs.getInt(4),
                    rs.getString(5),
                    rs.getInt(6),
                    rs.getInt(7),
                    rs.getInt(8),
                    rs.getInt(9),
                    rs.getInt(10)));



        }
return  first;
    }

selectsecont()

``

public ObservableList<Bemor> selectsecont() throws  SQLException{
    String Bemorid1=bemoridlar.toString().replace('[',' ');
    String bemoridlay=Bemorid1.replace(']',' ');
    ObservableList<Bemor> secont=FXCollections.observableArrayList();
    ConnectDb db =new ConnectDb();
    Connection connection =db.getConnection();
    Statement statement =connection.createStatement();
    String sql="SELECT bemor.fish, bolim.nomi, doktor.fish,bemor.navbat,xizmat.nomi,bemor.id,bolim.id,navbat.id,xizmat.id,doktor.id" +
            " FROM bemor JOIN doktor ON doktor.id=bemor.doktor_id " +
            "JOIN xizmat ON xizmat.id=doktor.xizmat_id " +
            "JOIN bolim ON bolim.id=xizmat.bolim_id " +
            "JOIN navbat ON navbat.doktor_id=doktor.id WHERE bemor.id NOT IN ('"+bemoridlay+"')   " ;

    ResultSet rs=statement.executeQuery(sql);
    while(rs.next())

    {
        secont.add(new Bemor(
                rs.getString(1),
                rs.getString(2),
                rs.getString(3),
                rs.getInt(4),
                rs.getString(5),
                rs.getInt(6),
                rs.getInt(7),
                rs.getInt(8),
                rs.getInt(9),
                rs.getInt(10)));
    }
    return secont;
}

`` Bemor对象

public class Bemor {

    String bemorism; //1
    String bolimnomi;
    String doktorism; //3
    int navbat;
    String xizmatturi; //5
    int bemor_id;
    int bolim_id; //7
    int navbat_id;
    int xizmat_id;//9
    int doktor_id;

    public int getDoktor_id() {
        return doktor_id;
    }

    public void setDoktor_id(int doktor_id) {
        this.doktor_id = doktor_id;
    }

    public Bemor(String bemorism, String bolimnomi, String doktorism, int navbat, String xizmatturi, int bemor_id, int bolim_id, int navbat_id, int xizmat_id, int doktor_id) {
        this.bemorism = bemorism;
        this.bolimnomi = bolimnomi;
        this.doktorism = doktorism;
        this.navbat = navbat;
        this.xizmatturi = xizmatturi;
        this.bemor_id = bemor_id;
        this.bolim_id = bolim_id;
        this.navbat_id = navbat_id;
        this.xizmat_id = xizmat_id;
        this.doktor_id=doktor_id;

    }

    public String getBemorism() {
        return bemorism;
    }

    public void setBemorism(String bemorism) {
        this.bemorism = bemorism;
    }

    public String getBolimnomi() {
        return bolimnomi;
    }

    public void setBolimnomi(String bolimnomi) {
        this.bolimnomi = bolimnomi;
    }

    public String getDoktorism() {
        return doktorism;
    }

    public void setDoktorism(String doktorism) {
        this.doktorism = doktorism;
    }

    public int getNavbat() {
        return navbat;
    }

    public void setNavbat(int navbat) {
        this.navbat = navbat;
    }

    public String getXizmatturi() {
        return xizmatturi;
    }

    public void setXizmatturi(String xizmatturi) {
        this.xizmatturi = xizmatturi;
    }

    public int getBemor_id() {
        return bemor_id;
    }

    public void setBemor_id(int bemor_id) {
        this.bemor_id = bemor_id;
    }

    public int getBolim_id() {
        return bolim_id;
    }

    public void setBolim_id(int bolim_id) {
        this.bolim_id = bolim_id;
    }

    public int getNavbat_id() {
        return navbat_id;
    }

    public void setNavbat_id(int navbat_id) {
        this.navbat_id = navbat_id;
    }

    public int getXizmat_id() {
        return xizmat_id;
    }

    public void setXizmat_id(int xizmat_id) {
        this.xizmat_id = xizmat_id;
    }
}

0 个答案:

没有答案