import java.sql.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class webiliides extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus)throws IOException, ServletException{ String kinganr=kysimus.getParameter("kinganumber"); String kingarv=kysimus.getParameter("kingaarv"); vastus.setContentType("text/plain"); PrintWriter valja=new PrintWriter(vastus.getWriter()); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn= DriverManager.getConnection("jdbc:odbc:kingapoebaas", "", ""); Statement st=cn.createStatement(); try{ String lause="CREATE TABLE kingatabel(kinganumber int, kingaarv int);"; st.executeUpdate(lause); }catch(Exception viga){ valja.println("Tabel on juba olemas!"); } String onking="SELECT count(*) as kingaarv FROM kingatabel where kinganumber="+kinganr+";"; valja.println(onking); ResultSet rs=st.executeQuery(onking); rs.next(); int kingadearv=rs.getInt("kingaarv"); //int jaak = kinganr - kingaarv; if(kingadearv==0){ valja.println("Lisatakse king"); String lause="INSERT INTO kingatabel (kinganumber,kingaarv) values ('"+kinganr+"','"+kingarv+"');"; st.executeUpdate(lause); }else{ String uus="UPDATE kingatabel set kingaarv=kingaarv+"+kingarv+" where kinganumber="+kinganr+";"; st.executeUpdate(uus); } valja.println("Andmed edukalt lisatud"); cn.close(); }catch(Exception viga){ valja.println("Probleem andmebaasiga: "+viga); } } }