-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd_to_cart.java
41 lines (41 loc) · 1.54 KB
/
Add_to_cart.java
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
import java.io.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.servlet.*;//For getting the generic servlet class
import javax.servlet.http.*;//For getting the HttpServlet class
public class Add_to_cart extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{
res.setContentType("text/html");
PrintWriter pw1=res.getWriter();
String nm1=req.getParameter("cart");
// pw1.println("<html><body bgcolor=skyblue>Welcome "+nm1+"<br> Enter your password: "+nm2+"<br> Address: "+nm3+"<br> Email: "+nm4+"<br> Security Question: "+nm5+"<br> Ans"+nm6+"<br> Hobbies: "+nm7+"</body></html>");//response from servlet
try
{
HttpSession ses=req.getSession();
String s1=(String)ses.getAttribute("mail");
ses.setAttribute("prod",nm1);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","Nayan");
Statement stmt=con.createStatement();
String q1="insert into cart values('"+s1+"','"+nm1+"')";
int x=stmt.executeUpdate(q1);
if(x>0)
{
pw1.println("Success");
}
else
{
pw1.println("Failure");
con.close();
}
}
catch(Exception e)
{
pw1.println(e);
}
}
}