import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class andmed4 extends HttpServlet {
public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus)
throws IOException, ServletException
{
vastus.setContentType("text/html");
PrintWriter valja = vastus.getWriter();
valja.println("");
valja.println("
");
valja.println("");
valja.println("Andmebaas\n");
valja.println("");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:AndmeBaas", "", "");
Statement st=cn.createStatement();
Statement st2=cn.createStatement();
Statement st3=cn.createStatement();
if(kysimus.getParameter("lisamine")!=null){
PreparedStatement ps2=cn.prepareStatement(
"INSERT INTO synniaeg (paev, kuu, aasta) VALUES (?, ?,?)"
);
String paev2=kysimus.getParameter("paev");
String kuu2=kysimus.getParameter("kuu");
String aasta2=kysimus.getParameter("aasta");
ps2.setString(1, paev2);
ps2.setString(2, kuu2);
ps2.setString(3, aasta2);
ps2.executeUpdate();
PreparedStatement ps3=cn.prepareStatement(
"INSERT INTO elukoht (maakond, linn, tanav, maja, korter) VALUES (?, ?, ?, ?, ?)"
);
String maakond2=kysimus.getParameter("maakond");
String linn2=kysimus.getParameter("linn");
String tanav2=kysimus.getParameter("tanav");
String maja2=kysimus.getParameter("maja");
String korter2=kysimus.getParameter("korter");
ps3.setString(1, maakond2);
ps3.setString(2, linn2);
ps3.setString(3, tanav2);
ps3.setString(4, maja2);
ps3.setString(5, korter2);
ps3.executeUpdate();
String idee= "SELECT max(id) FROM synniaeg";
ResultSet rs5= st2.executeQuery(idee);
rs5.next();
String mid=rs5.getString("max(id)");
String idee2= "SELECT max(id) FROM elukoht";
ResultSet rs6= st3.executeQuery(idee2);
rs6.next();
String mid2=rs6.getString("max(id)");
PreparedStatement ps=cn.prepareStatement(
"INSERT INTO inimesed (eesnimi, perenimi, synd, elupaik) VALUES (?, ?, ?, ?)"
);
ps.setString(1, kysimus.getParameter("eesnimi"));
ps.setString(2, kysimus.getParameter("perenimi"));
ps.setString(3, mid);
ps.setString(4, mid2);
ps.executeUpdate();
}
//***************************************************************************************************
valja.println("Lisamine
");
valja.println(
""
);
//***************************************************************************************************
cn.close();
valja.println("");
valja.println("");
}catch(Exception viga){
viga.printStackTrace(valja);}
}
}