import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class eksam2 extends HttpServlet{
public void doPost(HttpServletRequest kysimus,
HttpServletResponse vastus)
throws IOException, ServletException{
doGet(kysimus, vastus);
}
public void doGet(HttpServletRequest kysimus,
HttpServletResponse vastus)
throws IOException, ServletException{
vastus.setContentType("text/html");
PrintWriter valja=new PrintWriter(vastus.getWriter());
String t1 =kysimus.getParameter("textfield1");
String t2 =kysimus.getParameter("textfield2");
String t3 =kysimus.getParameter("textfield3");
String t4 =kysimus.getParameter("textfield4");
String t5 =kysimus.getParameter("textfield5");
try{
if (t1 !=null && t2 !=null && t3 !=null && t4 !=null ){
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:eksam", "", "");
Statement st=cn.createStatement();
String lause="INSERT INTO tabel (Nimi, Aadress, telefon, [E-mail]) values ('"+t1+"', '"+t2+"', '"+t3+"', '"+t4+"');";
//String lause="INSERT INTO tabel SET Nimi='"+t1+"', Aadress='"+t2+"', telefon='"+t3+"', E-mail='"+t4+"'";
// valja.println (lause);
st.executeUpdate(lause);
cn.close();
Connection cn1=DriverManager.getConnection("jdbc:odbc:eksam", "", "");
Statement st1=cn1.createStatement();
ResultSet rs1=st1.executeQuery("SELECT * FROM tabel;");
while(rs1.next()){
valja.println(rs1.getString("Nimi")+" "+rs1.getString("Aadress")+" "
+rs1.getString("telefon")+" "+rs1.getString("E-mail")+" "+rs1.getString("ID")+"
");
}
cn.close();
}
}catch(Exception e){e.printStackTrace(valja);} //kuvatakse kõik veateated
valja.println("\n