import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class lisamine 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");
try{
if (t1 !=null && t2 !=null && t3 !=null ){
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:rent", "", "");
Statement st=cn.createStatement();
String lause="INSERT INTO riistad (Tööriista_nimi, Maksumus, Kogus)"+
"values ('"+t1+"','"+t2+"','"+t3+"');";
st.executeUpdate(lause);
cn.close();
Connection cn1=DriverManager.getConnection("jdbc:odbc:rent", "", "");
Statement st1=cn1.createStatement();
ResultSet rs1=st1.executeQuery("SELECT * FROM riistad;");
while(rs1.next()){
valja.println(rs1.getString("Tööriista_nimi")+" "+rs1.getString("Maksumus")+" "
+rs1.getString("Kogus")+" "+rs1.getString("id")+"
");
}
cn.close();
}
}catch(Exception e){e.printStackTrace(valja);} //kuvatakse kõik veateated
valja.println("\n