import java.awt.*; import java.io.*; import java.sql.*; import java.text.*; import java.util.*; import javax.servlet.*; import java.awt.image.*; import javax.servlet.http.*; import com.sun.image.codec.jpeg.*; public class statistika extends HttpServlet { public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException { try{ ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",kysimus.getLocale()); vastus.setContentType("text/html"); PrintWriter out = vastus.getWriter(); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection("jdbc:odbc:Baas1"); Statement st=cn.createStatement(); out.println(""); out.println(""); out.println(" Statistika "); out.println(""); out.println(""); out.println(""); String id = kysimus.getParameter("id"); String paring = "SELECT * FROM Lingid WHERE id=" + id + ";"; ResultSet rs=st.executeQuery(paring); rs.next(); String link = rs.getString("Link"); String paring1 = "SELECT COUNT(*) as viisi FROM hinded WHERE hinne=5 AND lingi_id=" + id + ";"; ResultSet viis=st.executeQuery(paring1); viis.next(); int viisi = viis.getInt("viisi"); String paring2 = "SELECT COUNT(*) as nelju FROM hinded WHERE hinne=4 AND lingi_id=" + id + ";"; ResultSet neli=st.executeQuery(paring2); neli.next(); int neljasi = neli.getInt("nelju"); String paring3 = "SELECT COUNT(*) as kolmi FROM hinded WHERE hinne=3 AND lingi_id=" + id + ";"; ResultSet kolm=st.executeQuery(paring3); kolm.next(); int kolmesi = kolm.getInt("kolmi"); String paring4 = "SELECT COUNT(*) as kahtesi FROM hinded WHERE hinne=2 AND lingi_id=" + id + ";"; ResultSet kaks=st.executeQuery(paring4); kaks.next(); int kahtesi = kaks.getInt("kahtesi"); String paring5 = "SELECT COUNT(*) as yhtesi FROM hinded WHERE hinne=1 AND lingi_id=" + id + ";"; ResultSet yks=st.executeQuery(paring5); yks.next(); int yhtesi = yks.getInt("yhtesi"); String paring6 = "SELECT AVG(hinne) as keskmine from hinded WHERE lingi_id = " + id + ";"; ResultSet avg=st.executeQuery(paring6); avg.next(); double keskmine = avg.getDouble("keskmine"); cn.close(); out.println(""); out.println(""); out.println(""); out.println(""); out.println("

Saidi \"" + link + "\" hindamise statistika:

"); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println(""); out.println("
Viisi " + viisi + "
Nelju " + neljasi + "
Kolmi " + kolmesi + "
Kahtesi " + kahtesi + "
Ühtesi " + yhtesi + "
"); out.println("

Keskmine hinne: " + keskmine + "

<< Tagasi lingikataloogiVaata graafiliselt >>
"); out.println(""); out.println(""); }catch (Exception viga){viga.printStackTrace();} } }