Advertisement
aed1oN

Untitled

May 12th, 2021
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. public ArrayList<Grad> gradovi() {
  2.         ArrayList<Grad> rez = new ArrayList<>();
  3.         try {
  4.             ResultSet rsGrad = dajGradoveUpit.executeQuery();
  5.             while (rsGrad.next()) {
  6.                 Grad grad = new Grad(rsGrad.getInt(1), rsGrad.getString(2), rsGrad.getInt(3), null);
  7.                 Drzava drzava = null;
  8.                 ResultSet rsDrzava = dajDrzaveUpit.executeQuery();
  9.                 int drzavaId = rsGrad.getInt(4);
  10.                 while (rsDrzava.next()) {
  11.                     if ( rsDrzava.getInt(1) == drzavaId) {
  12.                         drzava = new Drzava(rsDrzava.getInt(1), rsDrzava.getString(2), grad);
  13.                     }
  14.                 }
  15.                 grad.setDrzava(drzava);
  16.                 rez.add(grad);
  17.             }
  18.             return rez;
  19.         } catch (SQLException e) {
  20.             e.printStackTrace();
  21.             return null;
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement