You are on page 1of 9

package p1;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class member extends HttpServlet
{
public void doPost(HttpServletRequest
request,HttpServletResponse response)throws
ServletException,IOException
{
Connection con=null;
Statement st=null;
Statement st1=null;
ResultSet rs=null;
ResultSet rs1=null;
Vector v = new Vector();
Statement st2=null;
ResultSet rs2=null;
Statement st3=null;
ResultSet rs3=null;

float a=0.0f;
String strid="";
String strid1="";
int slno1=0;
int ordno1=0;
String s5="";
String strItemid="";

int quantity=0;
int quantity1=0;
int quantity2=0;

float price=0.0f;
float amount=0.0f;
float total=0.0f;
float p1=0.0f ;
int q1 =0;

ServletContext sc = getServletContext();

s5=request.getParameter("custid");
System.out.println("ID"+s5);

response.setContentType("html/text");

String action=request.getParameter("getprice");
String action1=request.getParameter("submit");

String action2=request.getParameter("getamount");

System.out.println("gggggggggggggg"+action2);

strid=request.getParameter("itemid");
System.out.println("eeeeee"+strid);

if(action1 == null && action2==null){

if(action != null){

if(action.equalsIgnoreCase("getprice"))
{

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORA","ibp","ibp");

st=con.createStatement();
st1=con.createStatement();

rs = st.executeQuery("select itemid from item");


System.out.println(2);

strid=request.getParameter("itemid");
System.out.println("eeeeee"+strid);
sc.setAttribute("item1",strid);

s5=request.getParameter("custid");
System.out.println("ID"+s5);
sc.setAttribute("key11",s5);

rs1=st1.executeQuery("select uprice from item where itemid='"+strid+"'");


System.out.println(rs1);
System.out.println(4);

if(rs1.next())
{
System.out.println(5);

a=rs1.getFloat("uprice");
System.out.println(a);

if(rs1.next()!=true)
{
String ee=new Float(a).toString();
System.out.println(78);
sc.setAttribute("price1",ee);
System.out.println(79);
RequestDispatcher rd =sc.getRequestDispatcher("/ibp/xy.jsp");
System.out.println(80);
rd.forward(request,response);
}
else
{
RequestDispatcher rd = sc.getRequestDispatcher("/ibp/error.html");
rd.forward(request,response);
}
}

catch(Exception e)
{
System.out.println("Error");
}

}
}
}

if(action == null && action2 == null){


if(action1 != null){

if(action1.equalsIgnoreCase("submit"))
{

try
{

Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORA","ibp","ibp");

st = con.createStatement();
System.out.println(1);

st3= con.createStatement();
System.out.println(1);

slno1=Integer.parseInt(request.getParameter("slno"));
System.out.println(slno1);

ordno1=Integer.parseInt(request.getParameter("ordno"));
System.out.println(ordno1);
Integer d = new Integer(ordno1);

strid1=request.getParameter("item34");
System.out.println("eeeeee"+strid1);

price =Float.parseFloat(request.getParameter("price"));
System.out.println("price"+price);

quantity =Integer.parseInt(request.getParameter("quantity"));
System.out.println("quantity"+quantity);
Integer d1 = new Integer(quantity);

rs3=st3.executeQuery("select quantity from item where itemid='"+strid1+"'");


System.out.println(rs3);
System.out.println(4);

if(rs3.next())
{
System.out.println(5);

quantity1=rs3.getInt("quantity");
System.out.println(quantity1);

quantity2= quantity1-quantity ;

st3.executeUpdate("update item set quantity="+quantity2+" where itemid='"+strid1+"'");

amount=Float.parseFloat(request.getParameter("amount"));
System.out.println(amount);
Float d2 = new Float(amount);
v.addElement(d);
v.addElement(d1);
v.addElement(d2);

String s1 =(String)sc.getAttribute("key2");
System.out.println("jjjjjjjjjjjj"+s1);

s5=request.getParameter("custid");
System.out.println("ID"+s5);
sc.setAttribute("key11",s5);

int i=st.executeUpdate("insert into


order_detail( SLNO,ORDNO,ITEMID,QUANTITY,PRICE,AMOUNT)
values("+slno1+","+ordno1+",'"+strid1+"',"+quantity+","+price+","+amount+")");
System.out.println(i);

System.out.println("Successfully Inserted");

if(i>0)
{
s5=(String)sc.getAttribute("key11");
System.out.println(s5);
sc.setAttribute("key3",s5);

System.out.println(667);
sc.setAttribute("key",v);
System.out.println(778);

sc.setAttribute("key20",strid1);

RequestDispatcher rd = sc.getRequestDispatcher("/ibp/order.jsp");
System.out.println(723);
rd.forward(request,response);

}
else
{
RequestDispatcher rd = sc.getRequestDispatcher("/ibp/error.html");
rd.forward(request,response);

catch(Exception e)
{
System.out.println(e);

}
}
}
}

if(action1 == null && action == null){


if(action2!=null){

if(action2.equalsIgnoreCase("getamount"))
{

try
{
System.out.println("llllllllllllllll");
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORA","ibp","ibp");

int asl=0;
String aslno="";

int aord=0;
String aordno="";

st2 = con.createStatement();
System.out.println(1);

System.out.println("getamount");

p1 =Float.parseFloat(request.getParameter("price"));
System.out.println("price"+p1);

String pp=new Float(p1).toString();


sc.setAttribute("amt12",pp);

q1 =Integer.parseInt(request.getParameter("quantity"));
System.out.println("quantity"+q1);

String qq=new Integer(q1).toString();


sc.setAttribute("amt13",qq);
total += (p1*q1);
String amount1=new Float(total).toString();

sc.setAttribute("amt",amount1);

rs2=st2.executeQuery("select nvl((max(slno)+1),1) slno,nvl((max(ordno)+1),1) ordno from


order_detail");

System.out.println(45);

if(rs2.next())
{
System.out.println(5);

asl=rs2.getInt("slno");

System.out.println(asl);
aord=rs2.getInt("ordno");
System.out.println(aord);

if(rs2.next()!=true)

{
aslno=new Integer(asl).toString();
System.out.println(78);
sc.setAttribute("amt1",aslno);
aordno=new Integer(aord).toString();
System.out.println(81);
sc.setAttribute("amt2",aordno);

RequestDispatcher rd=sc.getRequestDispatcher("/ibp/xy.jsp");
System.out.println(80);
rd.forward(request,response);

catch(Exception e)
{
System.out.println("Error");
}

}
}
}

}
}

You might also like