-
Notifications
You must be signed in to change notification settings - Fork 0
/
card.jsp
62 lines (45 loc) · 1.38 KB
/
card.jsp
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
<%@ page
language="java"
import = "java.sql.*"
%>
<%
String pag=null;
String signup = (String)session.getAttribute("signup");
RequestDispatcher r;
if(signup==null){
if(pag==null)
pag="err.jsp?msg=You are not Autherized to Access this page";
}
if(pag!=null)
{
r = request.getRequestDispatcher(pag);
r.forward(request,response);
}
String card=request.getParameter("cardNo");
int amount=Integer.parseInt(request.getParameter("amount"));
int salary=Integer.parseInt(request.getParameter("income"));
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://127.0.0.1/bank";
Connection con=DriverManager.getConnection(url, "root", "root");
Statement st=con.createStatement();
PreparedStatement pst=con.prepareStatement("Select * from cardInfo where card=?");
pst.setString(1, card);
ResultSet rsp = pst.executeQuery();
if(rsp.next())
{
r = request.getRequestDispatcher("err.jsp?msg=card already exists");
r.forward(request,response);
}
else{
String query = "INSERT INTO cardInfo(card,amount,salary)VALUES('"+card+ "','"+ amount +"', '"+salary+"')" ;
int rs = st.executeUpdate( query );
if(rs>=1)
{ r = request.getRequestDispatcher("sucessmsg.jsp");
r.forward(request,response); }
else
{
r = request.getRequestDispatcher("err.jsp?msg=card addition failed");
r.forward(request,response);
}
}
%>