import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.StringTokenizer; public class eksam extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus) throws IOException, ServletException{ vastus.setContentType("text/html"); PrintWriter valja=new PrintWriter(vastus.getWriter()); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn=DriverManager.getConnection( "jdbc:odbc:baas", "", ""); Statement st=cn.createStatement(); Statement st1=cn.createStatement(); Statement st2=cn.createStatement(); String lause="SELECT * FROM Kahur;"; ResultSet rs=st.executeQuery(lause); String algus=kysimus.getParameter("algusaeg"); String l6pp=kysimus.getParameter("l6ppaeg"); String kasutaja=kysimus.getParameter("kasutaja"); String parool=kysimus.getParameter("parool"); if(algus != null && l6pp != null){ StringTokenizer stk1=new StringTokenizer(algus, " "); String AlgusKuup2ev=stk1.nextToken(); String AlgusKell=stk1.nextToken(); StringTokenizer stk2=new StringTokenizer(l6pp, " "); String L6ppKuup2ev=stk2.nextToken(); String L6ppKell=stk2.nextToken(); String lause1="INSERT INTO Kahur (AlgusKuup2ev, AlgusKell, L6ppKuup2ev, L6ppKell) values ('" + AlgusKuup2ev + "', '" + AlgusKell + "', '" + L6ppKuup2ev + "', '" + L6ppKell + "');"; st1.executeUpdate(lause1); } valja.println( "" + " Kahurite kasutamise ajad." + "
" + "

Tere. Kahurite teema mingi.


"+ "
" ); String lause2=("SELECT * FROM Kasutajad WHERE Kasutaja='" + kasutaja + "' and Parool='" + parool + "';"); ResultSet rs1=st2.executeQuery(lause2); if((kasutaja == null && parool == null) || (!rs1.next())){ valja.println( "
" + " Kasutajanimi
" + " Parool
" + "
" + "
" ); }else{ valja.println( " Kahuri(te) kasutusajad:
" + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " ); while( rs.next()){ valja.println( " " + " " + " " + " " + " " ); } valja.println( "
alguslõpp
" + rs.getDate("AlgusKuup2ev") + " kella " + rs.getTime("AlgusKell") + "-st" + rs.getDate("L6ppKuup2ev") + " " + rs.getTime("L6ppKell") +"-ni.
" + "
" + " " + "" ); cn.close(); } }catch(Exception ex){ ex.printStackTrace(valja); } } }