-
Notifications
You must be signed in to change notification settings - Fork 0
/
insuranceconfirm.java
103 lines (89 loc) · 4.66 KB
/
insuranceconfirm.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.jdbc.DB;
import java.sql.*;
public class insuranceconfirm extends HttpServlet {
public void init(ServletConfig config)
throws ServletException {
super.init(config);
}
public String getContext(String param) {
ServletContext sc=getServletContext();
String prop=sc.getInitParameter(param);
prop=prop!=null&&prop.length()>0?""+prop:"";
System.out.println("Contex param:"+prop);
return prop;
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
Connection c=null;
String name=request.getParameter("name");
String age=request.getParameter("age");
String sex=request.getParameter("sex");
String tm=request.getParameter("tm");
String ticketno=request.getParameter("ticketno");
String inamount=request.getParameter("inamount");
String cardno=request.getParameter("cardno");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String query =null;
int tkno=Integer.parseInt(ticketno);
int n=Integer.parseInt(tm);
try{
Connection conn=DB.getConnect();
Statement st=conn.createStatement();
int inrno=0;
ResultSet rs2=st.executeQuery("select * from insurance");
if(rs2.next())
{
query = new String("select max(insuranceno) as rno from insurance");
ResultSet rs3= st.executeQuery("select max(insuranceno) as rno from insurance");
if(rs3.next())
inrno= rs3.getInt(1) + 1;
}
else
inrno=5000;
ResultSet rs=null;
if(n==1) {
rs= st.executeQuery("select * from trainbooking where pnrno1 ="+tkno+"");
System.out.println("select * from flightbooking where reqno =("+tkno+")");
}
else if(n==2)
rs= st.executeQuery("select * from carbooking where reqno ="+tkno+"");
else if(n==3) {
rs= st.executeQuery("select * from flightbooking where reqno ="+tkno+"");
System.out.println("select * from flightbooking where reqno =("+tkno+")");
}
else if(n==4)
rs= st.executeQuery("select * from cruisebooking where reqno ="+tkno+"");
System.out.println("Choose option is :"+n);
if(rs.next()) {
query = new String("insert into insurance values('"+name+"','"+age+"','"+sex+"',"+tkno+",'"+inamount+"','"+cardno+"',"+inrno+")");
st.executeUpdate(query);
String relpath=new java.net.URL(request.getScheme(),request.getServerName(),request.getServerPort(),request.getContextPath()).toString();
getServletContext().getRequestDispatcher("/Pages/Common/Global.jsp").include(request,response);
out.println("<TABLE WIDTH=600 align=center cellspacing=0 cellpadding=4 style='font:bold 12px verdana;color:green'>");
out.println("<TR><Td align=center nowrap><BR>Search : <input type=text name=search class=input> <button accesskey='S'><u>S</u>earch</button> <a href='advanced.htm'>Advanced Search</a><BR><BR></Th></TR>");
out.println("<TR><TH bgcolor=#234567 colspan=2>Insurance Confirmation</TH></TR>");
out.println("<TR><TD align=center colspan=2><BR><BR>Your Insurance no. is <B><I>"+inrno+"</B></I><BR><font style='font:bold 15px tahoma'>Thanx for using the sevice</font><BR><BR></TH></TR>");
out.println("<TR><TD colspan=2 align=center><BR><BR><button onclick='location=\""+relpath+"/index.jsp\"' accesskey='C'><u>C</U>ontinue</button> <button onclick='location=\""+relpath+"/Pages/Signout.jsp\"' accesskey='S'><u>S</U>ignout</button></TD></TR>");
out.println("</TD></TR></tABLE><SCRIPT>setFooter(\""+relpath+"\",\""+relpath+"/Images/Back.jpg\")</SCRIPT>");
} else {
request.setAttribute("Response","Invalid Ticket No or Request No");
getServletContext().getRequestDispatcher("/Pages/Insurance.jsp").forward(request,response);
}
}catch(Exception e){
out.println("Exception"+e.getMessage()+e.toString());
}
finally{
try{
if(c!=null)
c.close();
}catch(Exception e){
out.println("Exception closing the connection"+e.getMessage());
}
}
}
}