.

Wednesday, January 26, 2011

class UpDeposit -online banking system

/* this code is intended education purpuse only. all rights reserved .copy right
protected .www.freejavaprojectsonline.blogspot.com . mails to : johnjustin@in.com */



import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;

public class UPDeposit extends HttpServlet{
Connection con;
Statement st;
ResultSet rs;
PreparedStatement ps,ps1;

public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException{
System.out.println("UpDeposit Loan:post");
try{
int ano=Integer.parseInt(req.getParameter("ANO"));

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:bank");
st=con.createStatement();

res.setContentType("text/html");
PrintWriter out=res.getWriter();

Calendar calendar = new GregorianCalendar();
String date=calendar.get(Calendar.DATE)+"/"+(calendar.get(Calendar.MONTH)+1)+"/"+calendar.get(Calendar.YEAR);

String type=req.getParameter("TYPE");

if (type.equals("CREDIT")){
ps1=con.prepareStatement("INSERT INTO FTABLE VALUES(?,?,?,?,?,SYSDATE)");

String sql="SELECT FID FROM FTABLE ORDER BY FID DESC";
rs=st.executeQuery(sql);
int fid=0;

if(rs.next())
fid=Integer.parseInt(rs.getString(1))+1;
else
fid=800;

int rfamount=Integer.parseInt(req.getParameter("AMOUNT"));
int rfduration=Integer.parseInt(req.getParameter("DURATION"));

rs=st.executeQuery("SELECT RATE FROM FITABLE WHERE DURATION="+rfduration);
rs.next();
int rate=Integer.parseInt(rs.getString("RATE"));
int tamount=(rfamount*rfduration*rate/100)+rfamount;
ps1.setInt(1,fid);
ps1.setInt(2,ano);
ps1.setInt(3,rfamount);
ps1.setInt(4,rfduration);
ps1.setInt(5,tamount);
ps1.executeUpdate();

ps=con.prepareStatement("INSERT INTO CREDITCARD VALUES(?,?,?,?,?,SYSDATE)");

String rctype=req.getParameter("CTYPE");
int rcno=Integer.parseInt(req.getParameter("CNO"));
String dfid="F"+fid;

ps.setInt(1,ano);
ps.setInt(2,rcno);
ps.setString(3,rctype);
ps.setString(4,dfid);
ps.setInt(5,rfamount);
ps.executeUpdate();

st.executeUpdate("COMMIT");
}
else if (type.equals("ACCOUNT")){
int rfamount=Integer.parseInt(req.getParameter("AMOUNT"));
int rfduration=Integer.parseInt(req.getParameter("DURATION"));

String sql="SELECT FID FROM FTABLE ORDER BY FID DESC";
rs=st.executeQuery(sql);
int fid=0;

if(rs.next())
fid=Integer.parseInt(rs.getString(1))+1;
else
fid=800;

rs=st.executeQuery("SELECT RATE FROM FITABLE WHERE DURATION="+rfduration);
rs.next();
int rate=Integer.parseInt(rs.getString("RATE"));
int tamount=(rfamount*rfduration*rate/100)+rfamount;

ps1=con.prepareStatement("INSERT INTO FTABLE VALUES(?,?,?,?,?,SYSDATE)");
ps1.setInt(1,fid);
ps1.setInt(2,ano);
ps1.setInt(3,rfamount);
ps1.setInt(4,rfduration);
ps1.setInt(5,tamount);
ps1.executeUpdate();

st.executeUpdate("COMMIT");
}

out.println("<html><head><title>Options</title></head>");
out.println("<body background=\"http:\\\\localhost:8080\\examples\\servlets\\images\\globe.jpg\" link=red alink=green vlink=blue>");
out.println("<h2 align=\"center\"><font color=\"#000080\">");
out.println("<img border=\"0\" src=\"http:\\\\localhost:8080\\examples\\servlets\\images\\earth.gif\" align=\"left\" width=\"50\" height=\"49\">");
out.println("</font></h2><h2 align=\"center\"><font color=\"#000080\">UNIVERSAL NET BANK");
out.println("</font></h2><p align=\"center\">&nbsp;</p>");
out.println("<table border=\"2\" width=\"100%\" bordercolorlight=\"#0000FF\" bordercolordark=\"#0000FF\">");
out.println("<tr><td width=\"12%\" valign=\"top\" align=\"center\">");
out.println("<a href=\"http:\\\\localhost:8080\\examples\\servlet\\Welcome?ANO="+ano+"\">Welcome");
out.println("</a></td><td width=\"18%\" valign=\"top\" align=\"center\">");
out.println("<a href=\"http:\\\\localhost:8080\\examples\\servlet\\ADetail?ANO="+ano+"\">Account Details");
out.println("</a></td><td width=\"14%\" valign=\"top\" align=\"center\">");
out.println("<a href=\"http:\\\\localhost:8080\\examples\\servlet\\WithDraw?ANO="+ano+"\">Withdrawals");
out.println("</a></td><td width=\"12%\" valign=\"top\" align=\"center\">");
out.println("<a href=\"http:\\\\localhost:8080\\examples\\servlet\\Loan?ANO="+ano+"\">Loans");
out.println("</a></td><td width=\"12%\" valign=\"top\" align=\"center\">");
out.println("<a href=\"http:\\\\localhost:8080\\examples\\servlet\\Mail?ANO="+ano+"\">Mail Us");
out.println("</a></td><td width=\"11%\" valign=\"top\" align=\"center\">");
out.println("<a href=\"http:\\\\localhost:8080\\examples\\servlets\\Logout.html\">Logout");
out.println("</a></td></tr></table><table border=\"0\" width=\"100%\">");
out.println("<tr><td width=\"50%\"><font color=\"#000080\"><b>");
out.println("Date&nbsp;&nbsp; :&nbsp; </b></font><font color=\"#000080\"><b>");
out.println(date);
out.println("</b></font></td><td width=\"50%\" align=\"right\"><font color=\"#000080\">");
out.println("<b>Account No : <font size=\"3\">");
out.println(ano);
out.println("</font></b></font></td></tr></table>");
out.println("<p align=\"center\">&nbsp;<img border=\"0\" src=\"http:\\\\localhost:8080\\examples\\servlets\\images\\deposits.jpg\" width=\"403\" height=\"83\"></p>");
out.println("</p><p align=\"left\"><b><font color=\"#000080\">");
out.println("Your Transactions Have been Successfully Completed.");
out.println("</font></b></p></body></html>");
}
catch(SQLException sqle4){
System.out.println("Sql4 Exception "+sqle4);
}
catch(ClassNotFoundException cnfe){
System.out.println("Class Not Found "+cnfe);
}
}
}




next =>class ViewLoans of online banking project

Google Ads