01 <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"  errorPage="" %>
02 <html>
03 <head>
04 <META HTTP-EQUIV="Refresh" CONTENT="10; URL=index3.jsp"
05 <title>.: Pizza :.</title>
06 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
07 </head>
08 
09 <body >
10 <h1>PIZZA-Service</h1>
11 <h3>Aktuelle Bestellung(en)..</h3><br>
12 
13 <%!
14   public void removeBestellung(String sql) {
15     try {
16       Class.forName("com.mysql.jdbc.Driver");
17       Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/project""root""");
18       Statement stmt = conn.createStatement();
19       stmt.executeUpdate(sql);
20       if (conn != null) {
21         conn.close();
22       }    
23     catch (Exception exc){}
24   }
25 %>
26 
27 
28 <%
29 
30 
31   String id2delete = request.getParameter"id" );
32   if (id2delete != null) {
33     removeBestellung("DELETE FROM bestellung where id = " + id2delete);
34     out.print("<script language='JavaScript'>");
35       out.print("alert('Bestellung wird ausgedruckt...');");
36     out.print("</script>");
37   }
38   
39   Class.forName("com.mysql.jdbc.Driver");
40   Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/project""root""");
41   Statement stmt = conn.createStatement();
42   ResultSet rs = stmt.executeQuery("SELECT b.id, pt.name, b.anzahl, (pt.preis * b.anzahl) AS Preis, '' As Bearbeiten  FROM bestellung b, pizza_type pt WHERE b.id_pizza = pt.id ORDER BY pt.id");
43   ResultSetMetaData rsmd = rs.getMetaData();
44   out.println("<table border='1'>");
45   
46   // header 
47   out.println("<tr>");
48   for(int i=2; i<=rsmd.getColumnCount(); i++) {
49     out.println("<td>");
50     out.println(rsmd.getColumnName(i));
51     out.println("</td>");
52   }
53   
54   // data
55   while (rs.next()) {  
56     out.println("<tr>");
57     for(int i=2; i<=rsmd.getColumnCount(); i++) {
58       out.println("<td>");
59       if (i == 5) {
60         int id = rs.getInt(1);
61         out.println("<a href='index3.jsp?id=" + id + "'>Bearbeiten</a></td>");
62       else {
63         out.println(rs.getObject(i));
64       }
65       out.println("</td>");
66     }
67     out.println("</tr>");
68   }
69   
70   out.println("</table>");
71   
72   if (conn != null) {
73     conn.close();
74   }
75   
76 %>
77 </html>