import java.io.*; import java.sql.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class done extends HttpServlet { public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException { PrintWriter out = vastus.getWriter(); try{ ResourceBundle rb = ResourceBundle.getBundle("LocalStrings",kysimus.getLocale()); vastus.setContentType("text/html"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection("jdbc:odbc:baas4"); Statement st=cn.createStatement(); Statement st2=cn.createStatement(); Statement st3=cn.createStatement(); out.println(""); out.println(""); out.println(" Saada "); out.println("
"+""+"
"); String a = kysimus.getParameter("valik"); String lause="SELECT laul, maa, id FROM lugu"; ResultSet rs=st.executeQuery(lause); while (rs.next()){ String saaja=rs.getString("id"); String punktid=kysimus.getParameter(saaja); if(punktid.length()>0){ String paring = "INSERT INTO punktid (andja_id, saaja_id, tulemus) VALUES (" + a + ", " + saaja + ", " + punktid +");"; st2.executeUpdate(paring); } } //String lause2="SELECT Sum(punktid.tulemus) AS summa, punktid.saaja_id FROM punktid GROUP BY punktid.saaja_id"; //ResultSet rs1=st.executeQuery(lause2); //while (rs1.next()){ //out.println(rs1.getString("summa")+ " ja selleks on " +rs1.getString("saaja_id")+"
"); //} String paring1="DELETE FROM abi"; st.executeUpdate(paring1); paring1="INSERT INTO abi SELECT Sum(punktid.tulemus) AS summa, punktid.saaja_id, lugu.maa FROM punktid, lugu WHERE lugu.id=punktid.saaja_id GROUP BY punktid.saaja_id, maa"; st.executeUpdate(paring1); String paring2 = "SELECT * FROM abi ORDER BY summa DESC, saaja_id ASC;"; ResultSet rs2=st.executeQuery(paring2); while(rs2.next()){ out.println(rs2.getString("summa")+ " punkti peal on " +rs2.getString("maa")+ "
"); } out.println(""); out.println(""); out.println(""); cn.close(); }catch (Exception viga){viga.printStackTrace(out);} } }