Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- Class.forName(Driver).newInstance();
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/vjezba4", "root", "");
- if(newID > 0 && newID < 23){
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT id, naziv, (SELECT COUNT(id) FROM mjesta WHERE idZup ="+newID+") AS brojMjesta FROM zupanije WHERE iD = "+newID+"");
- while (rs.next()) {
- int id = rs.getInt("id");
- String naziv = rs.getString("naziv");
- int brMjesta = rs.getInt("brojMjesta");
- Podaci podaci = new Podaci(id,naziv,brMjesta);
- request.setAttribute("podaci", podaci);
- }
- rd = request.getRequestDispatcher("pocetak.jsp");
- }
- else{
- out.println("KRIVO STE UNJELI ID!!!");
- rd = request.getRequestDispatcher("pocetak.jsp");
- }
- } catch (Exception e) {
- throw new IllegalStateException("Cannot connect the database!", e);
- }
- rd.forward(request, response);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement