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
| public class Paiement extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try
{
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
String dburl = "jdbc:odbc:donnes";
Connection con = DriverManager.getConnection(dburl,"","");
Statement stmt = con.createStatement();
Statement stm = con.createStatement();
String numcb=req.getParameter("num_carte");
String mois=req.getParameter("expmois");
String an=req.getParameter("expyear");
String clef=req.getParameter("cle");
ResultSet rs = stmt.executeQuery("select * from compte where num_CB='"+numcb+"' and exp_mois="+mois+" and exp_year="+an+" and cle="+clef+";");
if(rs.next())
{
int id = rs.getInt("id_client");out.println(id);
HttpSession masession = req.getSession();
Stack<String> panier = (Stack<String>)masession.getAttribute("panier");
if((panier!=null)&&(panier.size()>0))
{
int i=1; Float cout=null;ResultSet r ;
while(panier.size()-i>=0)
{
String name =panier.elementAt(panier.size()-i);
r = stmt.executeQuery("select * from article where id_article="+name);
if(r.next())
{
Date madate=new Date();
cout+=r.getFloat("prix");stm.executeUpdate("inset into vente values("+name+","+id+",'"+madate+"';");
}stm.executeUpdate("delete from article where id_article="+name);
i++;
r.close();
} |