1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package allo;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class oui extends HttpServlet
{
private Connection con;
private PrintWriter out;
public void init(ServletConfig conf) throws ServletException
{
super.init(conf);
try
{
Class.forName("com.mysql.jdbc.Driver");
con =DriverManager.getConnection ("jdbc:mysql://localhost:3306/test", "root", "mustapha");
}
catch(Exception e)
{
System.out.println("je suis la "+e);
}
}
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
try
{
out = res.getWriter();
out.println("<html><head><title>");
out.println("JDBC Servlet");
out.println("</title></head><body>");
out.println("merci");
String nom ="";
nom =req.getParameter("nom");
Statement instruction = con.createStatement();
int nbb = instruction.executeUpdate("INSERT INTO test1(nom) VALUES ('" + nom + "' )");
req.getRequestDispatcher("http://localhost:8080/merci/test.html").forward(req,res); mais çà fonctionne pas :cry:
}
catch(SQLException e)
{
out.println("Exception SQL"+ e);
}
catch(IOException e)
{
}
out.println("</body></html>");
out.close();
}
public void destroy()
{
try
{
con.close();
}
catch(SQLException e)
{
;
}
}
} |