CreateServlet.java

Similar documents
Complimentary material for the book Software Engineering in the Agile World

Author - Ashfaque Ahmed

ServletConfig Interface

CREATE A SERVLET PROGRAM TO DISPLAY THE STUDENTS MARKS. To create a servlet program to display the students marks

To create a view for students, staffs and courses in your departments using servlet/jsp.

Develop an Enterprise Java Bean for Banking Operations

Advanced Internet Technology Lab # 4 Servlets

Kamnoetvidya Science Academy. Object Oriented Programming using Java. Ferdin Joe John Joseph. Java Session

Servlet 5.1 JDBC 5.2 JDBC

Assignment -3 Source Code. Student.java

Université Antonine - Baabda

SQream Connector JDBC SQream Technologies Version 2.9.3

Unit-4: Servlet Sessions:

J2ME With Database Connection Program

CIS 3952 [Part 2] Java Servlets and JSP tutorial

JAVA SERVLET. Server-side Programming ADVANCED FEATURES

Distributed Systems Project 5 Assigned: Friday, April 6, 2012 Due: Friday, April 20, 11:59:59 PM

EJB - ACCESS DATABASE

WEB SERVICES EXAMPLE 2

Programming a Bank Database. We ll store the information in two tables: INTEGER DECIMAL(10, 2)

Servlets by Example. Joe Howse 7 June 2011

An implementation of Tree Panel component in EXT JS 4.0

JAVA SERVLET. Server-side Programming INTRODUCTION

JSP files for OBAAS1.1:

1. PhP Project. Create a new PhP Project as shown below and click next

JSP files for OBAAS1.2:

JdbcResultSet.java. import java.sql.*;

CSC System Development with Java. Database Connection. Department of Statistics and Computer Science. Budditha Hettige

Principles and Techniques of DBMS 6 JSP & Servlet

Fraud Detection And Integrity Of Database Without Using Pl-SQL Logic

Backend. (Very) Simple server examples

Getting started with Winstone. Minimal servlet container

JSP. Common patterns

CSE 530A. DAOs and MVC. Washington University Fall 2012

Servlet. 1.1 Web. 1.2 Servlet. HTML CGI Common Gateway Interface Web CGI CGI. Java Applet JavaScript Web. Java CGI Servlet. Java. Apache Tomcat Jetty

Accessing databases in Java using JDBC

Accessing EJB in Web applications

Penetration: from application down to OS

JDBC [Java DataBase Connectivity]

A.1 JSP A.2 JSP JSP JSP. MyDate.jsp page contenttype="text/html; charset=windows-31j" import="java.util.calendar" %>

SWE642 Oct. 22, 2003

Scheme G Sample Question Paper Unit Test 2

Prof. Edwar Saliba Júnior

&' () - #-& -#-!& 2 - % (3" 3 !!! + #%!%,)& ! "# * +,

JDBC, Transactions. Niklas Fors JDBC 1 / 38

Algorithmic Verification of Procedural Programs in the Presence of Code Variability

Tiers (or layers) Separation of concerns

Servlet. Web Server. Servlets are modules of Java code that run in web server. Internet Explorer. Servlet. Fire Fox. Servlet.

Integrate JPEGCAM with WaveMaker

Trusted Source SSO. Document version 2.3 Last updated: 30/10/2017.

Web based Applications, Tomcat and Servlets - Lab 3 -

Chair of Software Engineering. Java and C# in Depth. Prof. Dr. Bertrand Meyer. Exercise Session 9. Nadia Polikarpova

PARTIAL Final Exam Reference Packet

Server-side Web Programming

a. Jdbc:ids://localhost:12/conn?dsn=dbsysdsn 21. What is the Type IV Driver URL? a. 22.

Java Database Connectivity

// Static initializer block to load the JDBC Driver static {

e-pg Pathshala Subject: Computer Science Paper: Web Technology Module: JDBC INTRODUCTION Module No: CS/WT/26 Quadrant 2 e-text

Connection Pools. The ConnectionObject

DEZVOLTAREA APLICATIILOR WEB CURS 7. Lect. Univ. Dr. Mihai Stancu

Advanced Web Technology

Strut2 jasper report plugin - War deployment

Servlets Pearson Education, Inc. All rights reserved.

[I] SLT Operations & Maintenance (2009), OSP Maintenance Report, Annual Maintenance Report of Sri Lanka Telecom PLC, 4(3), pp 43-51

Distributed Systems Project 3 Assigned: Wednesday, October 2, 2013 Due Friday Oct 25, 11:59 PM

Appendix: Assorted Sweets

UNIVERSITY OF MUMBAI. Teacher s Reference Manual. Subject: Enterprise Java

( A ) 8. If the address of an array is stored in $value, how do you get the values of this array? (B) \$value (C) &$value (D) $$value

HL7 FHIR Data Consolidation Tool

A Reliable tool for Hospital Administration System

Prof. Edwar Saliba Júnior

Testing Web Database Applications. Yuetang Deng Phyllis Frankl Jiong Wang

Accessing a database from Java. Using JDBC

HTTP status codes. Setting status of an HTTPServletResponse

while (rs.next()) { String[] temp_array = {"","",""}; int prodid = rs.getint(1); temp_array[0] = ""+prodid;

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

ERwin and JDBC. Mar. 6, 2007 Myoung Ho Kim

DATABASE DESIGN I - 1DL300

You write standard JDBC API application and plug in the appropriate JDBC driver for the database the you want to use. Java applet, app or servlets

AJP. CHAPTER 5: SERVLET -20 marks

SDN Community Contribution

DB I. 1 Dr. Ahmed ElShafee, Java course

Allenhouse Institute of Technology (UPTU Code : 505) OOT Notes By Hammad Lari for B.Tech CSE V th Sem

Online Book Services

Race Conditions. A race condition occurs when an assumption needs to hold true for a period of time, but actually may not Bob and Alice example.

Advanced Topics in Operating Systems. Manual for Lab Practices. Enterprise JavaBeans

Generating the Server Response: HTTP Status Codes

OCP JavaEE 6 EJB Developer Study Notes

文字エンコーディングフィルタ 1. 更新履歴 2003/07/07 新規作成(第 0.1 版) 版 数 第 0.1 版 ページ番号 1

Servlet Basics. Agenda

Handout 31 Web Design & Development

Oracle Exam 1z0-809 Java SE 8 Programmer II Version: 6.0 [ Total Questions: 128 ]

CSC309: Introduction to Web Programming. Lecture 10

SERVLET AND JSP FILTERS

Input from Files. Buffered Reader

SQL DML and DB Applications, JDBC

2. Follow the installation directions and install the server on ccc. 3. We will call the root of your installation as $TOMCAT_DIR

EXPERIMENT- 9. Login.html

Database Application Development

Introduction to Servlets. After which you will doget it

Transcription:

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)