import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class counter extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException{ vastus.setContentType("text/plain"); PrintWriter valja=new PrintWriter(vastus.getWriter()); int counter; try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn= DriverManager.getConnection("jdbc:odbc:counter", "", ""); Statement st=cn.createStatement(); String lause="SELECT nr FROM counter WHERE id=1;"; ResultSet rs=st.executeQuery(lause); rs.next(); counter=rs.getInt("nr"); counter++; valja.println("Lehel on käidud: "+ counter +" korda."); String lause2="UPDATE counter SET nr= "+ counter+" WHERE id =1"; st.executeUpdate(lause2); cn.close(); }catch(Exception viga){ valja.println("Probleem andmebaasiga: " +viga); } } }