java - Join two tables in one list -


i want merge contents of 2 tables 1 list.i'm new programming , working on school project.i need data 2 tables shown in 1 table of application. current code works if have 2 rows in database,the application table shown both rows twice, if have 3 rows displayed 9 times , on. not want repeats.i hope understand question you.

i have in model:

public static observablelist<archivesmodel> takearchives () {         observablelist<archivesmodel> archives = fxcollections.observablearraylist();         try {             base.connect();             preparedstatement st= connection.preparestatement("select * destination,rent");                            resultset rs= st.executequery();                            while (rs.next()) {                     archivesmodel z;                 z = new archivesmodel(                         rs.getstring(first_destination),                         rs.getstring(last_destination),                         rs.getint(amount),                         rs.getstring(first_date),                         rs.getstring(last_date));                 archives .add(z);                                }             base.disconnected();                         } catch (sqlexception ex) {logger.getlogger(archivesmodel.class.getname()).log(level.severe, null, ex);         }         return archives;     } 

and in controller have

public void initialize(url url, resourcebundle rb) {         observablelist<archivesmodel> data = archivesmodel.takearchives();          first_destination.setcellvaluefactory(new propertyvaluefactory<archivesmodel, string>("first_destination"));         last_destination.setcellvaluefactory(new propertyvaluefactory<archivesmodel, string>("last_destination"));         amount.setcellvaluefactory(new propertyvaluefactory<archivesmodel, integer>("amount"));         first_date.setcellvaluefactory(new propertyvaluefactory<archivesmodel, string>("first_date"));         last_date.setcellvaluefactory(new propertyvaluefactory<archivesmodel, string>("last_date"));          archivesrenttbl.setitems(data);     }    

you need consider relations between 2 tables well. assuming both tables have key "rent_id" join both tables using following sql query:

select * destination join rent b on a.rent_id = b.rent_id 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -