import java.text.*; import java.sql.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class vaatamuuzik extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException{ PrintWriter valja=new PrintWriter(vastus.getWriter()); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn= DriverManager.getConnection("jdbc:odbc:andmed", "", ""); Statement st=cn.createStatement(); String idnr=kysimus.getParameter("id"); String haaled=kysimus.getParameter("haaled"); int punktid=0; // if (haaled.equals("1") || haaled.equals("2") || haaled.equals("3") || haaled.equals("4") || haaled.equals("5")){ String lause="UPDATE muuzik SET punktid=punktid+"+haaled+" WHERE id="+idnr+";"; st.executeUpdate(lause); lause="UPDATE muuzik SET haaled=haaled+1 WHERE id="+idnr+";"; st.executeUpdate(lause); lause="UPDATE muuzik SET keskmine=punktid/haaled WHERE id="+idnr+";"; st.executeUpdate(lause); // }else{ // } // String lause="SELECT id, esitaja, lugu, punktid, haaled, keskmine FROM muuzik ORDER BY keskmine DESC;"; ResultSet rs=st.executeQuery(lause); int nr=0; valja.println("

Top 10

"+ ""+ ""+ ""+ ""+ ""); int[] m_punktid=new int [100]; int[] m_id=new int [100]; int[] m_haaled=new int [100]; double[] m_keskmine=new double [100]; String[] m_esitaja=new String [100]; String[] m_lugu=new String [100]; DecimalFormat koma=new DecimalFormat("0.00"); while(rs.next()&& nr<10){ m_esitaja[nr]=rs.getString("esitaja"); m_lugu[nr]=rs.getString("lugu"); m_punktid[nr]=rs.getInt("punktid"); m_haaled[nr]=rs.getInt("haaled"); m_id[nr]=rs.getInt("id"); double komad=rs.getDouble("keskmine"); m_keskmine[nr]=komad; nr=nr+1; } nr=0; while(nr<10){ int arv=nr; int arv2=nr; if (m_keskmine[nr]==m_keskmine[nr+1]){ while (m_keskmine[arv2]==m_keskmine[nr]){ arv2++; } while (m_keskmine[arv]==m_keskmine[nr]){ valja.println(""); valja.println(""+ ""+ ""+ ""); arv++; } nr=arv; }else{ valja.println(""); valja.println(""+ ""+ ""+ ""); nr++; } } valja.println("
Koht
BändLugu
Hinne
"+ "
Hääli
"+(nr+1)+". - "+arv2+"."+"
"+m_esitaja[arv]+""+m_lugu[arv]+"
"+koma.format(m_keskmine[arv])+"
"+m_haaled[arv]+"
"+(nr+1)+"."+"
"+m_esitaja[nr]+""+m_lugu[nr]+"
"+koma.format(m_keskmine[nr])+"
"+m_haaled[nr]+"

Tagasi
"); cn.close(); }catch(Exception viga){ valja.println("Probleem andmebaasiga: " +viga); } } }