import java.sql.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Foorumlisaja extends HttpServlet{ public void doGet(HttpServletRequest kysimus, HttpServletResponse vastus)throws IOException, ServletException{ HttpSession hs=kysimus.getSession(); String name=hs.getAttribute("nimi").toString(); String teatetekst=kysimus.getParameter("teade"); vastus.setContentType("text/html"); PrintWriter valja=new PrintWriter(vastus.getWriter()); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection cn= DriverManager.getConnection("jdbc:odbc:king", "", ""); Statement st=cn.createStatement(); System.out.println("kaos"); String lause="INSERT INTO Foorum (nimi,tekst) values ('"+name+"','"+teatetekst+"');"; System.out.println(lause); st.executeUpdate(lause); valja.println( "\n"+ ""+ "
"+ "Teade on edukalt lisatud!"+ "
"+ "" ); cn.close(); }catch(Exception viga){ valja.println("Probleem andmebaasiga: "+viga); } } }