Classes in OBAAS 1.2: -------------------- The package name is pack_bank. Create this package in java source of your project. Create classes as per the class names provided here. You can then copy the source code from this file and paste them in the correct classes. CreateServlet.java -------------------------------------------------------------------------------------------------- import java.io.ioexception; import java.io.printwriter; import java.rmi.naming; import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import javax.servlet.requestdispatcher; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; //This is the controller class for user inputs and redirecting to different pieces of codes for processing public class CreateServlet extends HttpServlet /** * */ private static final long serialversionuid = 1L; public void doget(httpservletrequest request, HttpServletResponse response) throws ServletException, IOException response.setcontenttype("text/html"); PrintWriter out=response.getwriter(); int status; int ano; int err=0; double amount = 0; double phone = 0; String username=request.getparameter("username"); String password=request.getparameter("password"); String repassword=request.getparameter("repassword"); String amoun=request.getparameter("amount"); if(amoun!= null) amount=double.parsedouble(amoun); String adderess=request.getparameter("adderess"); String ph=request.getparameter("phone"); if(ph!= null) phone=double.parsedouble(ph); String catg=request.getparameter("cat"); String acno=request.getparameter("acno"); //account number is checked to see if it already exists (if user account already created) or not if(acno!= null) ano=integer.parseint(acno); else ano = 0; String reqtype=request.getparameter("req_type"); //here it is checked to see if an account has at least $5 balance so that cheque book can be issued if(ano > 0)
boolean stat=verifylogin.checklogin(ano,username,password); if(stat==true) try ps = con.preparestatement("select * from NEWACCOUNT where accountno='"+ano+"'"); ResultSet rs; rs = ps.executequery(); if(rs.next()) if(rs.getint(5)>5) status=registeruser.regchq(ano, reqtype); // //if(registeruser.regchq(ano, reqtype)>0) //out.print("your chequebook request has been accepted."); RequestDispatcher rd=request.getrequestdispatcher("cheque_res.jsp"); else //if balance less than $5 then cheque book can not be issues err = 2; catch (SQLException e) // TODO Auto-generated catch block else //Incorrect User Name, Password or Account No err = 1; else status=registeruser.register(username, password, repassword, amount, adderess, phone, catg); if(status>0) //out.print("welcome! YOUR ACCOUNT HAS OPENED"); RequestDispatcher rd=request.getrequestdispatcher("create_res.jsp"); else //Registration failed err = 3; DBInitializer.java -----------------------------------------------------------------------------------------------
public interface DBInitializer String DRIVER="oracle.jdbc.driver.OracleDriver"; String CON_STRING="jdbc:oracle:thin:@localhost:1521:xe"; String USERNAME="bankuser"; String PASSWORD="bankuser"; GetCon.java ----------------------------------------------------------------------------------------------------- import java.sql.*; import java.io.*; public class GetCon private GetCon() public static Connection con; static try Class.forName(DBInitializer.DRIVER); con=drivermanager.getconnection(dbinitializer.con_string,dbinitializer.username,dbinitializer.password); catch (ClassNotFoundException e) catch (SQLException e) System.out.println("Exception in GetCon"); public static Connection getcon() return con; public static int getprimarykey() int nextvalue=0; PreparedStatement ps2; try ps2=con.preparestatement("select bank_seq.nextval from dual"); ResultSet rs=ps2.executequery(); rs.next(); nextvalue=rs.getint(1); System.out.println(nextvalue); catch (SQLException e) return nextvalue; RegisterUser.java ---------------------------------------------------------------------------------------------------- import java.sql.*; //This class is used for creating new account and new cheque book service request import pack_bank.getcon;
public class RegisterUser static int status=0; //This class creates records for new account and new cheque book request public static int register(string username,string password,string repassword,double amount,string adderess,double phone, String category) try ps = con.preparestatement("insert into NEWACCOUNT values(?,?,?,?,?,?,?,?)"); int nextvalue1=getcon.getprimarykey(); ps.setint(1,nextvalue1); ps.setstring(2,username); ps.setstring(3,password); ps.setstring(4,repassword); ps.setdouble(5,amount); ps.setstring(6,adderess); ps.setdouble(7,phone); ps.setstring(8,category); catch (SQLException e) public static int regchq(int acno, String reqtype) try ps = con.preparestatement("insert into chequebook values(?,?,?)"); int nextvalue1=getcon.getprimarykey(); double amt=0; ps.setint(1,acno); ps.setint(2,nextvalue1); ps.setstring(3,reqtype); String whr; whr = " where accountno = "; whr = whr + acno; ps = con.preparestatement("select amount from newaccount" + whr); ResultSet rs1=ps.executequery(); while(rs1.next()) String amount=rs1.getstring(1); amt=double.parsedouble(amount); amt = amt - 5; ps = con.preparestatement("update newaccount set amount = " + amt + whr); catch (SQLException e) VerifyLogin.java --------------------------------------------------------------------------------------------------- import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception;
//This class checks any request from user by validating the user from database records public class VerifyLogin public static boolean checklogin(int accountno,string username,string password) boolean status=false; try PreparedStatement ps=con.preparestatement("select * from NEWACCOUNT where accountno=? and username =? and password =?"); ps.setint(1,accountno); ps.setstring(2,username); ps.setstring(3,password); ResultSet rs=ps.executequery(); status=rs.next(); catch (SQLException e)