Advertisement
Guest User

Untitled

a guest
May 10th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. try {
  2.            
  3.             Class.forName(Driver).newInstance();
  4.             Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/vjezba4", "root", "");
  5.             if(newID > 0 && newID < 23){
  6.                 Statement stmt = con.createStatement();
  7.                 ResultSet rs = stmt.executeQuery("SELECT id, naziv, (SELECT COUNT(id) FROM mjesta WHERE idZup ="+newID+") AS brojMjesta FROM zupanije WHERE iD = "+newID+"");
  8.                 while (rs.next()) {
  9.                    
  10.                     int id = rs.getInt("id");
  11.                     String naziv = rs.getString("naziv");
  12.                     int brMjesta = rs.getInt("brojMjesta");
  13.                     Podaci podaci = new Podaci(id,naziv,brMjesta);
  14.                     request.setAttribute("podaci", podaci);
  15.                 }
  16.                 rd = request.getRequestDispatcher("pocetak.jsp");
  17.             }
  18.             else{
  19.                 out.println("KRIVO STE UNJELI ID!!!");
  20.                 rd = request.getRequestDispatcher("pocetak.jsp");
  21.             }
  22.         } catch (Exception e) {
  23.             throw new IllegalStateException("Cannot connect the database!", e);
  24.         }
  25.        
  26.         rd.forward(request, response);
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement