├── Account.java
├── AccountOverview.jsp
├── CheckingAccount.java
├── DBConnection.java
├── Deposit.jsp
├── Display.html
├── EnquireTransaction.java
├── LoginServlet.java
├── Logo.html
├── OpenBankAccount.jsp
├── README.md
├── SavingAccount.java
├── SignUp.html
├── SignUp.jsp
├── SignUpServlet.java
├── Transaction.java
├── Transfer.jsp
├── Withdraw.jsp
├── afterlogin.jsp
├── index.html
└── login.html
/Account.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Program Author: Kavita Mishra for CSCI 6810 Java and the Internet *
3 | * Date: September, 2018 *
4 | *******************************************************************************/
5 |
6 | package com.mishra;
7 |
8 | import java.lang.*; //including Java packages used by this program
9 | import java.sql.*;
10 | import com.mishra.*;
11 |
12 | public class Account
13 | {
14 | private String Username, Password, Password1, Name;
15 |
16 | public Account(String UN, String PassW, String PassW1, String NM) {
17 | Username = UN;
18 | Password = PassW;
19 | Password1 = PassW1;
20 | Name = NM;
21 | }
22 |
23 | public Account(String UN, String PassW) {
24 | Username = UN;
25 | Password = PassW;
26 | }
27 |
28 | public boolean signUp() {
29 | boolean done = !Username.equals("") && !Password.equals("") && !Password1.equals("") && Password.equals(Password1);
30 | try {
31 | if (done) {
32 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
33 | Connection DBConn = ToDB.openConn();
34 | Statement Stmt = DBConn.createStatement();
35 | String SQL_Command = "SELECT Username FROM Account WHERE Username ='"+Username+"'"; //SQL query command
36 | ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username exsits.
37 | done = done && !Rslt.next();
38 | if (done) {
39 | SQL_Command = "INSERT INTO Account(Username, Password, Name) VALUES ('"+Username+ "','"+Password+"','"+Name+"')"; //Save the username, password and Name
40 | Stmt.executeUpdate(SQL_Command);
41 | }
42 | Stmt.close();
43 | ToDB.closeConn();
44 | }
45 | }
46 | catch(java.sql.SQLException e)
47 | { done = false;
48 | System.out.println("SQLException: " + e);
49 | while (e != null)
50 | { System.out.println("SQLState: " + e.getSQLState());
51 | System.out.println("Message: " + e.getMessage());
52 | System.out.println("Vendor: " + e.getErrorCode());
53 | e = e.getNextException();
54 | System.out.println("");
55 | }
56 | }
57 | catch (java.lang.Exception e)
58 | { done = false;
59 | System.out.println("Exception: " + e);
60 | e.printStackTrace ();
61 | }
62 | return done;
63 | }
64 | public String signIn()
65 | {
66 | boolean done = !Username.equals("") && !Password.equals("");
67 | try
68 | {
69 | if (done)
70 | {
71 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
72 | Connection DBConn = ToDB.openConn();
73 | Statement Stmt = DBConn.createStatement();
74 | String SQL_Command = "SELECT Name FROM Account WHERE Username ='"+Username+ "'AND Password ='"+Password+"'"; //SQL query command
75 | ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username and password exsits.
76 | done = done && Rslt.next();
77 | if (done)
78 | {
79 | Name=Rslt.getString(1);
80 | }
81 | Stmt.close();
82 | ToDB.closeConn();
83 | }
84 |
85 | }
86 | catch(java.sql.SQLException e)
87 | { done = false;
88 | System.out.println("SQLException: " + e);
89 | while (e != null)
90 | { System.out.println("SQLState: " + e.getSQLState());
91 | System.out.println("Message: " + e.getMessage());
92 | System.out.println("Vendor: " + e.getErrorCode());
93 | e = e.getNextException();
94 | System.out.println("");
95 | }
96 | }
97 | catch (java.lang.Exception e)
98 | { done = false;
99 | System.out.println("Exception: " + e);
100 | e.printStackTrace ();
101 | }
102 | return Name;
103 | }
104 |
105 | public boolean changePassword(String NewPassword) { //5
106 | boolean done = false;
107 | try { //20
108 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
109 | Connection DBConn = ToDB.openConn();
110 | Statement Stmt = DBConn.createStatement();
111 | String SQL_Command = "SELECT * FROM Account WHERE Username ='"+Username+ "'AND Password ='"+Password+"'"; //SQL query command
112 | ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username exsits.
113 | if (Rslt.next()) {
114 | SQL_Command = "UPDATE Account SET Password='"+NewPassword+"' WHERE Username ='"+Username+"'"; //Save the username, password and Name
115 | Stmt.executeUpdate(SQL_Command);
116 | Stmt.close();
117 | ToDB.closeConn();
118 | done=true;
119 | }
120 | }
121 | catch(java.sql.SQLException e) //5
122 | { done = false;
123 | System.out.println("SQLException: " + e);
124 | while (e != null)
125 | { System.out.println("SQLState: " + e.getSQLState());
126 | System.out.println("Message: " + e.getMessage());
127 | System.out.println("Vendor: " + e.getErrorCode());
128 | e = e.getNextException();
129 | System.out.println("");
130 | }
131 | }
132 | catch (java.lang.Exception e)
133 | { done = false;
134 | System.out.println("Exception: " + e);
135 | e.printStackTrace ();
136 | }
137 | return done;
138 | }
139 | }
--------------------------------------------------------------------------------
/AccountOverview.jsp:
--------------------------------------------------------------------------------
1 |
7 | <%@ page import="java.io.*" %>
8 | <%@ page import="java.util.*" %>
9 | <%@ page import="java.lang.*" %>
10 | <%@ page import="Com.Gandhi.*;" %>
11 |
12 | <%
13 | String UName = new String("");
14 | UName = request.getParameter( "UserID" );
15 | //out.println("Your username is " + UName);
16 |
17 | String Name = new String("");
18 | Name = request.getParameter("CustomerName");
19 | //out.println("Your customername is " + Name);
20 |
21 |
22 | CheckingAccount ca;
23 | SavingsAccount sa;
24 | ca = new CheckingAccount();
25 | ca.getAccountInfo(UName);
26 | sa = new SavingsAccount();
27 | sa.getAccountInfo(UName);
28 |
29 | %>
30 |
31 |
32 |
33 |
57 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/CheckingAccount.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Program Author: Dr. Yongming Tang for CSCI 6810 Java and the Internet *
3 | * Date: October, 2013 *
4 | *******************************************************************************/
5 | package com.mishra;
6 |
7 | import java.lang.*; //including Java packages used by this program
8 | import java.sql.*;
9 | import com.mishra.*;
10 |
11 | public class CheckingAccount
12 | { //Instance Variables
13 | private String CheckingAccountNumber, CustomerName, CustomerID;
14 | private float Balance = -1, Amount = -1;
15 |
16 | public CheckingAccount(String CA_Num, String Cust_Name, String Cust_ID, String Amt) { //Constructor One with three parameters
17 | CheckingAccountNumber = CA_Num;
18 | CustomerName = Cust_Name;
19 | CustomerID = Cust_ID;
20 | //Balance = Float.parseFloat(Bal);
21 | Amount = Float.parseFloat(Amt);
22 | }
23 |
24 |
25 |
26 | public CheckingAccount(String CA_Num) { //Constructor Two with one parameter
27 | CheckingAccountNumber = CA_Num;
28 | }
29 | public CheckingAccount() { //Constructor with no parameters for fetching the account no.
30 | }
31 |
32 |
33 | public boolean openAcct() {
34 | boolean done = false;
35 | try {
36 | if (!done) {
37 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
38 | Connection DBConn = ToDB.openConn();
39 | Statement Stmt = DBConn.createStatement();
40 | String SQL_Command = "SELECT CheckingAccountNumber FROM CheckingAccount WHERE CheckingAccountNumber ='"+CheckingAccountNumber+"'"; //SQL query command
41 | ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username exsits.
42 | done = !Rslt.next();
43 | if (done) {
44 | SQL_Command = "INSERT INTO CheckingAccount(CheckingAccountNumber, CustomerName, Balance, CustomerID)"+
45 | " VALUES ('"+CheckingAccountNumber+"','"+CustomerName+"',"+Amount+", '"+CustomerID+"')"; //Save the username, password and Name
46 | Stmt.executeUpdate(SQL_Command);
47 | }
48 | Stmt.close();
49 | ToDB.closeConn();
50 | }
51 | }
52 | catch(java.sql.SQLException e)
53 | { done = false;
54 | System.out.println("SQLException: " + e);
55 | while (e != null)
56 | { System.out.println("SQLState: " + e.getSQLState());
57 | System.out.println("Message: " + e.getMessage());
58 | System.out.println("Vendor: " + e.getErrorCode());
59 | e = e.getNextException();
60 | System.out.println("");
61 | }
62 | }
63 | catch (java.lang.Exception e)
64 | { done = false;
65 | System.out.println("Exception: " + e);
66 | e.printStackTrace ();
67 | }
68 | return done;
69 | }
70 | public String getAccno(String C_ID) { //Method to return a CheckingAccount No.
71 | try {
72 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
73 | Connection DBConn = ToDB.openConn();
74 | Statement Stmt = DBConn.createStatement();
75 | String SQL_Command = "SELECT CheckingAccountNumber FROM CheckingAccount WHERE CustomerID ='"+C_ID+"'";
76 | ResultSet Rslt = Stmt.executeQuery(SQL_Command);
77 |
78 | while (Rslt.next()) {
79 | CheckingAccountNumber = Rslt.getString("CheckingAccountNumber");
80 |
81 | }
82 | Stmt.close();
83 | ToDB.closeConn();
84 | }
85 | catch(java.sql.SQLException e)
86 | {
87 | System.out.println("SQLException: " + e);
88 | while (e != null)
89 | { System.out.println("SQLState: " + e.getSQLState());
90 | System.out.println("Message: " + e.getMessage());
91 | System.out.println("Vendor: " + e.getErrorCode());
92 | e = e.getNextException();
93 | System.out.println("");
94 | }
95 | }
96 | return CheckingAccountNumber;
97 | }
98 | public float getBalance() { //Method to return a CheckingAccount balance
99 | try {
100 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
101 | Connection DBConn = ToDB.openConn();
102 | Statement Stmt = DBConn.createStatement();
103 | String SQL_Command = "SELECT Balance FROM CheckingAccount WHERE CheckingAccountNumber ='"+CheckingAccountNumber+"'"; //SQL query command for Balance
104 | ResultSet Rslt = Stmt.executeQuery(SQL_Command);
105 |
106 | while (Rslt.next()) {
107 | Balance = Rslt.getFloat(1);
108 | }
109 | Stmt.close();
110 | ToDB.closeConn();
111 | }
112 | catch(java.sql.SQLException e)
113 | {
114 | System.out.println("SQLException: " + e);
115 | while (e != null)
116 | { System.out.println("SQLState: " + e.getSQLState());
117 | System.out.println("Message: " + e.getMessage());
118 | System.out.println("Vendor: " + e.getErrorCode());
119 | e = e.getNextException();
120 | System.out.println("");
121 | }
122 | }
123 | catch (java.lang.Exception e)
124 | {
125 | System.out.println("Exception: " + e);
126 | e.printStackTrace ();
127 | }
128 | return Balance;
129 | }
130 |
131 | public float getBalance(String ChkAcctNumber) { //Method to return a CheckingAccount balance
132 | try {
133 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
134 | Connection DBConn = ToDB.openConn();
135 | Statement Stmt = DBConn.createStatement();
136 | String SQL_Command = "SELECT Balance FROM CheckingAccount WHERE CheckingAccountNumber ='"+ChkAcctNumber+"'"; //SQL query command for Balance
137 | ResultSet Rslt = Stmt.executeQuery(SQL_Command);
138 |
139 | while (Rslt.next()) {
140 | Balance = Rslt.getFloat(1);
141 | }
142 | Stmt.close();
143 | ToDB.closeConn();
144 | }
145 | catch(java.sql.SQLException e)
146 | {
147 | System.out.println("SQLException: " + e);
148 | while (e != null)
149 | { System.out.println("SQLState: " + e.getSQLState());
150 | System.out.println("Message: " + e.getMessage());
151 | System.out.println("Vendor: " + e.getErrorCode());
152 | e = e.getNextException();
153 | System.out.println("");
154 | }
155 | }
156 | catch (java.lang.Exception e)
157 | {
158 | System.out.println("Exception: " + e);
159 | e.printStackTrace ();
160 | }
161 | return Balance;
162 | }
163 |
164 | public boolean deposit(String C_ID){
165 |
166 | boolean done= !CheckingAccountNumber.equals("") && !CustomerID.equals("");
167 |
168 | try{
169 | if(done){
170 | DBConnection DBconn = new DBConnection();
171 | Connection conn = DBconn.openConn();
172 | Statement stat = conn.createStatement();
173 | String SQL_Command = "SELECT Balance FROM CheckingAccount WHERE CheckingAccountNumber = '"+CheckingAccountNumber+"' AND CustomerID ='"+C_ID+"'";
174 | System.out.println(SQL_Command);
175 | ResultSet reslt = stat.executeQuery(SQL_Command);
176 |
177 | while (reslt.next()) {
178 | Balance = reslt.getFloat(1);
179 | }
180 | Balance = Balance + Amount;
181 | SQL_Command = "UPDATE CheckingAccount SET Balance = '" + Balance + "' WHERE CheckingAccountNumber = '"+CheckingAccountNumber+"'";
182 | System.out.println(SQL_Command);
183 | stat.executeUpdate(SQL_Command);
184 | stat.close();
185 | DBconn.closeConn();
186 | }
187 | }
188 |
189 | catch (SQLException e){
190 | System.out.println("SQLException" + e);
191 | done= false;
192 | System.out.println("SQLExceptionState" + e.getSQLState());
193 | System.out.println("message" + e.getMessage());
194 | System.out.println("vendor" + e.getErrorCode());
195 | e.getNextException();
196 | System.out.println("");
197 | }
198 |
199 | catch (java.lang.Exception e){
200 |
201 | System.out.println("Exception" + e);
202 | e.printStackTrace();
203 | }
204 |
205 | return done;
206 | }
207 | public boolean Withdraw(String C_ID){
208 |
209 | boolean done = !CheckingAccountNumber.equals("") && !CustomerID.equals("");
210 |
211 | try{
212 | if(done){
213 | DBConnection DBconn = new DBConnection();
214 | Connection Conn = DBconn.openConn();
215 | Statement Stat = Conn.createStatement();
216 | String SQL_Command = "SELECT Balance FROM CheckingAccount WHERE CheckingAccountNumber = '"+CheckingAccountNumber+"' AND CustomerID= '"+C_ID+"' ";
217 | System.out.println(SQL_Command);
218 | ResultSet rslt = Stat.executeQuery(SQL_Command);
219 | while (rslt.next()) {
220 | Balance = rslt.getFloat(1);
221 | }
222 | if (Balance>=Amount) {
223 | Balance = Balance - Amount;
224 | SQL_Command = "UPDATE CheckingAccount SET Balance = '"+Balance+"' WHERE CheckingAccountNumber = '"+CheckingAccountNumber+"'";
225 | System.out.println(SQL_Command);
226 | Stat.executeUpdate(SQL_Command);
227 | Stat.close();
228 | DBconn.closeConn();
229 |
230 | }
231 | }
232 | }
233 | catch (java.sql.SQLException e){
234 |
235 | System.out.println("SQLException" + e);
236 | while (e != null){
237 | System.out.println("SqlExceptionState" + e.getSQLState());
238 | System.out.println("Message"+ e.getMessage());
239 | System.out.println("Vendor"+ e.getErrorCode());
240 |
241 | e = e.getNextException();
242 | System.out.println("");
243 |
244 | }
245 | }
246 | catch (java.lang.Exception e){
247 |
248 | System.out.println("Exception" + e);
249 |
250 | e.printStackTrace();
251 |
252 | }
253 | return done;
254 | }
255 | }
--------------------------------------------------------------------------------
/DBConnection.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Program Author: Dr. Yongming Tang for CSCI 6810 Java and the Internet *
3 | * Date: September, 2012 *
4 | *******************************************************************************/
5 |
6 | package com.mishra;
7 |
8 | import java.util.*;
9 | import java.sql.*;
10 |
11 | public class DBConnection {
12 |
13 | private Connection connection;
14 | private String URL;
15 |
16 | public DBConnection() {
17 | //URL = "jdbc:odbc:JavaClass";
18 | URL ="jdbc:sqlserver://127.0.0.1:1433;databaseName=JavaClass;integratedSecurity=true;";//"user=tang;password=;
19 | connection = null;
20 |
21 | }
22 |
23 | public Connection openConn() {
24 | try {
25 | //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
26 | Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
27 | connection = DriverManager.getConnection(URL);
28 | //connection = DriverManager.getConnection(URL, "tang", "xxxxxx");
29 | }
30 | catch ( Exception e ) {
31 | e.printStackTrace();
32 | connection = null;
33 | }
34 | return connection;
35 | }
36 |
37 | public void closeConn() {
38 | try {
39 | connection.close();
40 | }
41 | catch( Exception e ) {
42 | System.err.println ("Can't close the database connection.");
43 | }
44 | }
45 |
46 | public Vector getNextRow(ResultSet rs,ResultSetMetaData rsmd) throws SQLException
47 | {
48 | Vector currentRow = new Vector();
49 |
50 | for(int i=1;i<=rsmd.getColumnCount();i++)
51 | switch(rsmd.getColumnType(i))
52 | {
53 | case Types.VARCHAR:
54 | case Types.LONGVARCHAR:
55 | currentRow.addElement(rs.getString(i));
56 | break;
57 | case Types.INTEGER:
58 | currentRow.addElement(new Long(rs.getLong(i)));
59 | break;
60 | case Types.DOUBLE:
61 | currentRow.addElement(new Double(rs.getDouble(i)));
62 | break;
63 | case Types.FLOAT:
64 | currentRow.addElement(new Float(rs.getFloat(i)));
65 | break;
66 | default:
67 | System.out.println("Type was: "+ rsmd.getColumnTypeName(i));
68 | }
69 |
70 | return currentRow;
71 | }
72 | }
--------------------------------------------------------------------------------
/Deposit.jsp:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Display.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | In order to have a service, please log on to the system first!
6 | |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/EnquireTransaction.java:
--------------------------------------------------------------------------------
1 | package com.mishra;
2 |
3 | import java.util.*;
4 | import java.sql.*;
5 | import com.mishra.*;
6 |
7 | public class EnquireTransaction {
8 | private String UName, StartDate, EndDate;
9 | private Vector C_Names, Rows;
10 | public Vector[] FetchTransaction(String Uname,String StartDate,String EndDate) {
11 | boolean done = !StartDate.equals("") && !EndDate.equals("");
12 | try {
13 | Vector C_Names = new Vector();
14 | Vector Rows = new Vector();
15 | if (done)
16 | {
17 | C_Names.addElement("Trans_Number");
18 | C_Names.addElement("Trans_Amount");
19 | C_Names.addElement("Trans_Time");
20 | C_Names.addElement("Trans_Date");
21 | C_Names.addElement("From_Acc");
22 | C_Names.addElement("To_Acc");
23 | C_Names.addElement("Trans_Type");
24 |
25 | DBConnection ToDB = new DBConnection();
26 | Connection DBConn = ToDB.openConn();
27 | Statement stmt = DBConn.createStatement();
28 | String SQL_Command = " SELECT * FROM Transactions WHERE CustomerID = '"+UName+"' AND TransactionDate BETWEEN '"+StartDate+"' AND '"+EndDate+"'";
29 | ResultSet rslt = stmt.executeQuery(SQL_Command);
30 | ResultSetMetaData rsmd = rslt.getMetaData();
31 | while(rslt.next())
32 | {
33 | DBConnection DC = new DBConnection();
34 | Rows.addElement(DC.getNextRow(rslt,rsmd));
35 | int CN = rsmd.getColumnCount();
36 | for (int i = 0; i<=CN; i++)
37 | {
38 | C_Names.addElement(rsmd.getColumnName(CN));
39 | }
40 | }
41 | stmt.close();
42 | ToDB.closeConn();
43 | }
44 | }
45 |
46 | catch(java.sql.SQLException e)
47 | {done = false;
48 | System.out.println("SQLException: " + e);
49 | while (e != null)
50 | {System.out.println("SQLState: " + e.getSQLState());
51 | System.out.println("Message: " + e.getMessage());
52 | System.out.println("Vendor: " + e.getErrorCode());
53 | e = e.getNextException();
54 | System.out.println("");
55 | }
56 | }
57 | catch (java.lang.Exception e)
58 | {done = false;
59 | System.out.println("Exception: " + e);
60 | e.printStackTrace ();
61 | }
62 | Vector[] TransInfo = new Vector[2];
63 | TransInfo[0] = C_Names;
64 | TransInfo[1] = Rows;
65 | return TransInfo;
66 | }
67 | }
68 |
69 |
70 |
71 |
--------------------------------------------------------------------------------
/LoginServlet.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Program Author: Dr. Yongming Tang for CSCI 6810 Java and the Internet *
3 | * Date: September, 2012 *
4 | *******************************************************************************/
5 |
6 | import java.io.*;
7 | import javax.servlet.*; //package for GenericServlet
8 | import javax.servlet.http.*; //package for HttpServlet
9 | import java.util.*;
10 | import com.mishra.*;
11 |
12 | public class LoginServlet extends HttpServlet {
13 | private String Username, Password;
14 | private PrintWriter output;
15 |
16 | //a method called automatically to initialize the servlet
17 | public void init( ServletConfig config ) throws ServletException
18 | {
19 | super.init( config );
20 | Username = new String("");
21 | Password = new String("");
22 | }
23 |
24 | //a method included in class HttpServlet to respond
25 | //to post requests from a client.
26 | public void doGet ( HttpServletRequest req, HttpServletResponse res )
27 | throws ServletException, IOException
28 | { doPost(req, res);
29 | }
30 |
31 | //a method included in class HttpServlet to respond
32 | //to post requests from a client.
33 | public void doPost ( HttpServletRequest req, HttpServletResponse res )
34 | throws ServletException, IOException
35 | {
36 | //obtains a character-based output stream that enables
37 | //text data to be sent to the client
38 | output = res.getWriter();
39 |
40 | //specifies the MIME type of the response to the browser
41 | res.setContentType( "text/html" );
42 |
43 | //returns the value associated with a parameter sent to
44 | //the servlet as part of a post request
45 | Username = req.getParameter( "UserName" );
46 | Password = req.getParameter( "PassWord" );
47 | Account Acct = new Account(Username, Password);
48 | String CustomerName = Acct.signIn();
49 | if (!CustomerName.equals("")){
50 | System.out.println("login username=" + Username);
51 | //showSuccess();
52 | req.setAttribute("Username", Username);
53 | req.setAttribute("CustomerName", CustomerName);
54 | req.getRequestDispatcher("/CSCI6810/afterlogin.jsp").forward(req, res);
55 | }else
56 | output.println("login failed");
57 | }
58 |
59 |
60 | //this "cleanup" method is called when a servlet is terminated by the server
61 | public void destroy() {
62 | output.close();
63 | }
64 | }
--------------------------------------------------------------------------------
/Logo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Welcome to Bank of Java!
4 |
5 |
6 |
--------------------------------------------------------------------------------
/OpenBankAccount.jsp:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Online-Banking-System-using-Java
2 | This was a project in my Java class where I had to develop an online banking system with the use cases provided by the professor.
3 |
4 | Based on the use case, I had to do the following so that a customer can open a checking account and/or a savings account.
5 | 1. Create tables CheckingAccount(CheckingAccountNumber, CustomerName, Balance, CustomerID), SavingsAccount(SavingsAccountNumber, CustomerName, Balance, InterestRate, CustomerID), Transactions(TransactionNumber, TransactionAmount, TransactionType, TransactionTime, TransactionDate, FromAccount, ToAccount, CustomerID). Use varchar(50) for any non-numerical value including AccountNumber and TransactionNumber, and float for any numerical value. CustomerID here means Username.
6 | 2. Study entity class CheckingAccount.java, and then develop your entity classes SavingsAccount.java and Transaction.java that has a method for recording a transaction.
7 | 3. Add necessary statements to OpenBankAccountControl.java to open both Checking and Savings accounts, and record the transactions of opening deposits.
8 |
9 | In continuation to the above, had to do then do the following:
10 |
11 | Develop use cases of Account Overview, Inquire Transactions, Deposit, and Withdraw by using the services from your bank as examples. And develop your Java programs to fully implement the functionalities with access to database. Assume that a customer has two accounts, Savings Account and Checking Account. Account Overview shows the current balances of customers’ Savings Account and Checking Account. Inquire Transactions allow customers to search specific transactions by entering a starting date and ending date.
12 | 1. Develop methods deposit(), withdraw() in your classes CheckingAccount and SavingsAccount, getBalance() and calculateInterests() in class SavingsAccount, searchTransaction() in class Transactions. Then implement Transfer, Deposit, and Withdraw functionalities. It means that your program shows Transfer, Deposit, or Withdraw after successful login. Your current program is to show Open Bank Account window after successful login. Modifications are necessary.
13 | 2. Organize these functionalities as tabs in one window. The default tab is Account Overview. Please combine Open Account into this application. Show the window after successful login. These tabs must be in your window, Account Overview, Open Account, Deposit, Withdraw, Transfer and Inquire Transactions subtabs.
14 |
15 |
--------------------------------------------------------------------------------
/SavingAccount.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Program Author: Kavita Mishra for CSCI 6810 Java and the Internet *
3 | * Date: September, 2018 *
4 | *******************************************************************************/
5 | package com.mishra;
6 |
7 | import java.lang.*; //including Java packages used by this program
8 | import java.sql.*;
9 | import com.mishra.*;
10 |
11 | public class SavingAccount
12 | { //Instance Variables
13 | private String SavingAccountNumber, CustomerName, CustomerID;
14 | private float Balance = -1, Amount = -1;
15 |
16 | public SavingAccount(String SA_Num, String Cust_Name, String Cust_ID, String Amt) { //Constructor One with three parameters
17 | SavingAccountNumber = SA_Num;
18 | CustomerName = Cust_Name;
19 | CustomerID = Cust_ID;
20 | Amount = Float.parseFloat(Amt);
21 | }
22 |
23 | public SavingAccount(String SA_Num) { //Constructor Two with one parameter
24 | SavingAccountNumber = SA_Num;
25 | }
26 | public SavingAccount(){
27 | }
28 | public boolean openAcct() {
29 | boolean done = false;
30 | try {
31 | if (!done) {
32 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
33 | Connection DBConn = ToDB.openConn();
34 | Statement Stmt = DBConn.createStatement();
35 | String SQL_Command = "SELECT SavingAccountNumber FROM SavingAccount WHERE SavingAccountNumber ='"+SavingAccountNumber+"'"; //SQL query command
36 | ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username exsits.
37 | done = !Rslt.next();
38 | if (done) {
39 | SQL_Command = "INSERT INTO SavingAccount(SavingAccountNumber, CustomerName, Balance, CustomerID)"+
40 | " VALUES ('"+SavingAccountNumber+"','"+CustomerName+"','"+Amount+"', '"+CustomerID+"')"; //Save the username, password and Name
41 | Stmt.executeUpdate(SQL_Command);
42 | }
43 | Stmt.close();
44 | ToDB.closeConn();
45 | }
46 | }
47 | catch(java.sql.SQLException e)
48 | { done = false;
49 | System.out.println("SQLException: " + e);
50 | while (e != null)
51 | { System.out.println("SQLState: " + e.getSQLState());
52 | System.out.println("Message: " + e.getMessage());
53 | System.out.println("Vendor: " + e.getErrorCode());
54 | e = e.getNextException();
55 | System.out.println("");
56 | }
57 | }
58 | catch (java.lang.Exception e)
59 | { done = false;
60 | System.out.println("Exception: " + e);
61 | e.printStackTrace ();
62 | }
63 | return done;
64 | }
65 | public String getAccno(String C_ID) { //Method to return a SavingAccount No.
66 | try {
67 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
68 | Connection DBConn = ToDB.openConn();
69 | Statement Stmt = DBConn.createStatement();
70 | String SQL_Command = "SELECT SavingAccountNumber FROM SavingAccount WHERE CustomerID ='"+C_ID+"'";
71 | ResultSet Rslt = Stmt.executeQuery(SQL_Command);
72 |
73 | while (Rslt.next()) {
74 | SavingAccountNumber = Rslt.getString("SavingAccountNumber");
75 |
76 | }
77 | Stmt.close();
78 | ToDB.closeConn();
79 | }
80 | catch(java.sql.SQLException e)
81 | {
82 | System.out.println("SQLException: " + e);
83 | while (e != null)
84 | { System.out.println("SQLState: " + e.getSQLState());
85 | System.out.println("Message: " + e.getMessage());
86 | System.out.println("Vendor: " + e.getErrorCode());
87 | e = e.getNextException();
88 | System.out.println("");
89 | }
90 | }
91 | return SavingAccountNumber;
92 | }
93 | public float getBalance() { //Method to return a SavingAccount balance
94 | try {
95 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
96 | Connection DBConn = ToDB.openConn();
97 | Statement Stmt = DBConn.createStatement();
98 | String SQL_Command = "SELECT Balance FROM SavingAccount WHERE SavingAccountNumber ='"+SavingAccountNumber+"'"; //SQL query command for Balance
99 | ResultSet Rslt = Stmt.executeQuery(SQL_Command);
100 |
101 | while (Rslt.next()) {
102 | Balance = Rslt.getFloat(1);
103 | }
104 | Stmt.close();
105 | ToDB.closeConn();
106 | }
107 | catch(java.sql.SQLException e)
108 | {
109 | System.out.println("SQLException: " + e);
110 | while (e != null)
111 | { System.out.println("SQLState: " + e.getSQLState());
112 | System.out.println("Message: " + e.getMessage());
113 | System.out.println("Vendor: " + e.getErrorCode());
114 | e = e.getNextException();
115 | System.out.println("");
116 | }
117 | }
118 | catch (java.lang.Exception e)
119 | {
120 | System.out.println("Exception: " + e);
121 | e.printStackTrace ();
122 | }
123 | return Balance;
124 | }
125 |
126 | public float getBalance(String SaveAcctNumber) { //Method to return a SavingAccount balance
127 | try {
128 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
129 | Connection DBConn = ToDB.openConn();
130 | Statement Stmt = DBConn.createStatement();
131 | String SQL_Command = "SELECT Balance FROM SavingAccount WHERE SavingAccountNumber ='"+SaveAcctNumber+"'"; //SQL query command for Balance
132 | ResultSet Rslt = Stmt.executeQuery(SQL_Command);
133 |
134 | while (Rslt.next()) {
135 | Balance = Rslt.getFloat(1);
136 | }
137 | Stmt.close();
138 | ToDB.closeConn();
139 | }
140 | catch(java.sql.SQLException e)
141 | {
142 | System.out.println("SQLException: " + e);
143 | while (e != null)
144 | { System.out.println("SQLState: " + e.getSQLState());
145 | System.out.println("Message: " + e.getMessage());
146 | System.out.println("Vendor: " + e.getErrorCode());
147 | e = e.getNextException();
148 | System.out.println("");
149 | }
150 | }
151 | catch (java.lang.Exception e)
152 | {
153 | System.out.println("Exception: " + e);
154 | e.printStackTrace ();
155 | }
156 | return Balance;
157 | }
158 | public boolean deposit(String C_ID){
159 |
160 | boolean done= !SavingAccountNumber.equals("") && !CustomerID.equals("");
161 |
162 | try{
163 | if(done){
164 | DBConnection DBconn = new DBConnection();
165 | Connection conn = DBconn.openConn();
166 | Statement stat = conn.createStatement();
167 | String SQL_Command = "SELECT Balance FROM SavingAccount WHERE SavingAccountNumber = '"+SavingAccountNumber+"' AND CustomerID ='"+C_ID+"'";
168 | System.out.println(SQL_Command);
169 | ResultSet reslt = stat.executeQuery(SQL_Command);
170 |
171 | while (reslt.next()) {
172 | Balance = reslt.getFloat(1);
173 | }
174 | Balance = Balance + Amount;
175 |
176 | SQL_Command = "UPDATE SavingAccount SET Balance = '" + Balance + "' WHERE SavingAccountNumber = '"+SavingAccountNumber+"'";
177 | System.out.println(SQL_Command);
178 | stat.executeUpdate(SQL_Command);
179 | stat.close();
180 | DBconn.closeConn();
181 | }
182 | }
183 |
184 | catch (SQLException e){
185 | System.out.println("SQLException" + e);
186 | done= false;
187 | System.out.println("SQLExceptionState" + e.getSQLState());
188 | System.out.println("message" + e.getMessage());
189 | System.out.println("vendor" + e.getErrorCode());
190 | e.getNextException();
191 | System.out.println("");
192 | }
193 |
194 | catch (java.lang.Exception e){
195 |
196 | System.out.println("Exception" + e);
197 | e.printStackTrace();
198 | }
199 |
200 | return done;
201 | }
202 | public boolean Withdraw(String C_ID){
203 |
204 | boolean done = !SavingAccountNumber.equals("") && !CustomerID.equals("") && !(Balance == 0);
205 |
206 | try{
207 | if(done){
208 | DBConnection DBconn = new DBConnection();
209 | Connection Conn = DBconn.openConn();
210 | Statement Stat = Conn.createStatement();
211 |
212 | String SQL_Command = "SELECT Balance FROM SavingAccount WHERE SavingAccountNumber = '"+SavingAccountNumber+"' AND CustomerID= '"+C_ID+"' ";
213 | System.out.println(SQL_Command);
214 | ResultSet rslt = Stat.executeQuery(SQL_Command);
215 | while (rslt.next())
216 | {
217 | Balance = rslt.getFloat(1);
218 | }
219 | if (Balance>=Amount) {
220 | Balance = Balance - Amount;
221 | SQL_Command = "UPDATE SavingAccount SET Balance = '"+Balance+"' WHERE SavingAccountNumber = '"+SavingAccountNumber+"'";
222 | System.out.println(SQL_Command);
223 | Stat.executeUpdate(SQL_Command);
224 | Stat.close();
225 | DBconn.closeConn();
226 |
227 | }
228 |
229 | }
230 | }
231 | catch (java.sql.SQLException e){
232 |
233 | System.out.println("SQLException" + e);
234 | while (e != null){
235 | System.out.println("SqlExceptionState" + e.getSQLState());
236 | System.out.println("Message"+ e.getMessage());
237 | System.out.println("Vendor"+ e.getErrorCode());
238 |
239 | e = e.getNextException();
240 | System.out.println("");
241 |
242 | }
243 | }
244 | catch (java.lang.Exception e){
245 |
246 | System.out.println("Exception" + e);
247 |
248 | e.printStackTrace();
249 |
250 | }
251 | return done;
252 | }
253 | }
--------------------------------------------------------------------------------
/SignUp.html:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 | Sign Up
11 |
12 |
13 |
14 | Welcome to our online registration!
15 |
16 |
30 |
31 |
32 |
33 |
61 |
--------------------------------------------------------------------------------
/SignUp.jsp:
--------------------------------------------------------------------------------
1 |
7 |
8 | <%@ page import="java.io.*" %>
9 | <%@ page import="java.util.*" %>
10 | <%@ page import="java.lang.*" %>
11 | <%@ page import="com.mishra.*;" %>
12 |
13 | <%
14 | String Username = new String("");
15 | String Password = new String("");
16 | String Re_enterPassword = new String("");
17 | String FullName = new String("");
18 |
19 | Username = request.getParameter( "UsernameField" );
20 | Password = request.getParameter( "PasswordField" );
21 | Re_enterPassword = request.getParameter( "RePasswordField" );
22 | FullName = request.getParameter( "NameField" );
23 |
24 | Account Acct = new Account(Username, Password, Re_enterPassword, FullName);
25 | %>
26 | <%
27 | if (!Acct.signUp())
28 | out.println("Account creation failed because of existing username or invalid username. Please try again!");
29 | else {
30 | %>
31 |
32 |
33 |
34 | Congratulations! You have an account with us. Thank you! You can login now.
35 |
52 |
53 |
71 |
72 |
73 | <% }
74 | %>
75 |
76 |
--------------------------------------------------------------------------------
/SignUpServlet.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Program Author: Dr. Yongming Tang for CSCI 6810 Java and the Internet *
3 | * Date: September, 2012 *
4 | *******************************************************************************/
5 |
6 | import java.io.*;
7 | import javax.servlet.*; //package for GenericServlet
8 | import javax.servlet.http.*; //package for HttpServlet
9 | import java.util.*;
10 | //import Course.Java.ProSample.*;
11 | import com.mishra.*;
12 |
13 | public class SignUpServlet extends HttpServlet {
14 | private String Username, Password, Re_enterPassword, CustomerName;
15 | private PrintWriter output;
16 |
17 | //a method called automatically to initialize the servlet
18 | public void init( ServletConfig config )
19 | throws ServletException
20 | {
21 | super.init( config );
22 | Username = new String("");
23 | Password = new String("");
24 | Re_enterPassword = new String("");
25 | CustomerName = new String("");
26 |
27 | }
28 |
29 | //a method included in class HttpServlet to respond
30 | //to post requests from a client.
31 | public void doGet ( HttpServletRequest req, HttpServletResponse res )
32 | throws ServletException, IOException
33 | { doPost(req, res);
34 | }
35 |
36 | //a method included in class HttpServlet to respond
37 | //to post requests from a client.
38 | public void doPost ( HttpServletRequest req, HttpServletResponse res )
39 | throws ServletException, IOException
40 | {
41 | //obtains a character-based output stream that enables
42 | //text data to be sent to the client
43 | output = res.getWriter();
44 |
45 | //specifies the MIME type of the response to the browser
46 | res.setContentType( "text/html" );
47 |
48 | //returns the value associated with a parameter sent to
49 | //the servlet as part of a post request
50 | Username = req.getParameter( "UsernameField" );
51 | Password = req.getParameter( "PasswordField" );
52 | Re_enterPassword = req.getParameter( "RePasswordField" );
53 | CustomerName = req.getParameter( "NameField" );
54 |
55 | Account Acct = new Account(Username, Password, Re_enterPassword, CustomerName);
56 | if (Acct.signUp())
57 | showSuccess();
58 | else
59 | output.println("Account creation failed because of existing username or invalid username. Please try again!");
60 | }
61 |
62 | public void showSuccess()
63 | {
64 | StringBuffer Buf = new StringBuffer();
65 | Buf.append("\n");
66 | Buf.append("\n");
67 | Buf.append("Congratulations! You have an account with us. Thank you! You can login now.
\n");
68 | Buf.append("\n");
88 | Buf.append("\n");
89 |
90 | Buf.append("\n");
109 | Buf.append("\n");
110 | output.println(Buf.toString());
111 | }
112 |
113 | //this "cleanup" method is called when a servlet is terminated by the server
114 | public void destroy() {
115 | output.close();
116 | }
117 | }
--------------------------------------------------------------------------------
/Transaction.java:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * Program Author: Kavita Mishra for CSCI 6810 Java and the Internet *
3 | * Date: September, 2018 *
4 | *******************************************************************************/
5 | package com.mishra;
6 |
7 | import java.lang.*; //including Java packages used by this program
8 | import java.sql.*;
9 | import java.util.Random;
10 | import java.time.format.DateTimeFormatter;
11 | import java.time.LocalDateTime;
12 | import java.time.LocalTime;
13 | import java.time.LocalDate;
14 | import java.util.*;
15 | import com.mishra.*;
16 |
17 | public class Transaction
18 | { //Instance Variables
19 | private String TransactionNumber, TransactionType, TransactionTime, TransactionDate, FromAccount, ToAccount, CustomerID;
20 | private float Amount = -1;
21 | private String Startdate, Enddate;
22 | private Vector TransStore = new Vector();
23 |
24 |
25 |
26 | public Transaction(String AccountType, String Cust_ID, String Amt){
27 | ToAccount = AccountType;
28 | CustomerID = Cust_ID;
29 | Amount = Float.parseFloat(Amt);
30 | }
31 |
32 | public Transaction(String ToAcc, String FromAcc, String Cust_ID, String Amt, String Trans_type) { //Constructor One with four parameters
33 | ToAccount = ToAcc;
34 | FromAccount = FromAcc;
35 | CustomerID = Cust_ID;
36 | TransactionType = Trans_type;
37 | Amount = Float.parseFloat(Amt);
38 | }
39 | public Transaction(String SD, String ED){
40 |
41 | Startdate = SD;
42 | Enddate = ED;
43 | }
44 |
45 |
46 | public String recordTransaction() {
47 | boolean done = true;
48 | try {
49 | if (done) {
50 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
51 | Connection DBConn = ToDB.openConn();
52 | Statement Stmt = DBConn.createStatement();
53 | String SQL_Command;
54 | while(done) {
55 | Random rand = new Random();
56 | int n = rand.nextInt(9999) + 1000;
57 | TransactionNumber = Integer.toString(n);
58 | SQL_Command = "SELECT TransactionNumber FROM Transactions WHERE TransactionNumber ='"+TransactionNumber+"'"; //SQL query command
59 | ResultSet Rslt = Stmt.executeQuery(SQL_Command); //Inquire if the username exsits.
60 | done = Rslt.next();
61 | }
62 | if (!done) {
63 | LocalTime nowTime = java.time.LocalTime.now();
64 | LocalDate nowDate = java.time.LocalDate.now();
65 | DateTimeFormatter formatterTime = DateTimeFormatter.ofPattern("HH:mm:ss");
66 | DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern("yyyy-MM-dd");
67 | TransactionTime = nowTime.format(formatterTime);
68 | TransactionDate = nowDate.format(formatterDate);
69 | //TransactionType = "Deposit";
70 | SQL_Command = "INSERT INTO Transactions(TransactionNumber, TransactionType, TransactionAmount, TransactionTime, TransactionDate, FromAccount, ToAccount, CustomerID)"+
71 | " VALUES ('"+TransactionNumber+"','"+TransactionType+"','"+Amount+"','"+TransactionTime+"', '"+TransactionDate+"', '"+FromAccount+"', '"+ToAccount+"', '"+CustomerID+"')"; //Save the username, password and Name
72 | Stmt.executeUpdate(SQL_Command);
73 | }
74 | Stmt.close();
75 | ToDB.closeConn();
76 | }
77 | }
78 | catch(java.sql.SQLException e)
79 | { done = false;
80 | System.out.println("SQLException: " + e);
81 | while (e != null)
82 | { System.out.println("SQLState: " + e.getSQLState());
83 | System.out.println("Message: " + e.getMessage());
84 | System.out.println("Vendor: " + e.getErrorCode());
85 | e = e.getNextException();
86 | System.out.println("");
87 | }
88 | }
89 | catch (java.lang.Exception e)
90 | { done = false;
91 | System.out.println("Exception: " + e);
92 | e.printStackTrace ();
93 | }
94 | return TransactionNumber;
95 | }
96 | public Vector searchTransaction(String UName){
97 | boolean done;
98 |
99 | try {
100 | done = !Startdate.equals("") && !Enddate.equals("");
101 | DBConnection ToDB = new DBConnection(); //Have a connection to the DB
102 | Connection DBConn = ToDB.openConn();
103 | Statement Stmt = DBConn.createStatement();
104 | String SQL_Command = "SELECT * FROM Transactions WHERE TransactionDate BETWEEN '"+Startdate+ "' AND '"+Enddate+ "'"; //SQL query command
105 | ResultSet Rslt = Stmt.executeQuery(SQL_Command);
106 | while (Rslt.next()) {
107 | Vector Column_Names = new Vector();
108 |
109 | String TransNumber = Rslt.getString("TransactionNumber");
110 | String TransAmount = Rslt.getString("TransactionAmount");
111 | String TransType = Rslt.getString("TransactionType");
112 | String TransTime = Rslt.getString("TransactionTime");
113 | String TransDate = Rslt.getString("TransactionDate");
114 | String FromAcc = Rslt.getString("FromAccount");
115 | String ToAcc = Rslt.getString("ToAccount");
116 | Column_Names.add(0, TransNumber);
117 | Column_Names.add(1, TransAmount);
118 | Column_Names.add(2, TransType);
119 | Column_Names.add(3, TransTime);
120 | Column_Names.add(4, TransDate);
121 | Column_Names.add(5, FromAcc);
122 | Column_Names.add(6, ToAcc);
123 | TransStore.add(Column_Names);
124 | }
125 | }
126 | catch(SQLException e)
127 | {
128 | System.out.println("SQLException: " + e);
129 | while (e != null)
130 | { System.out.println("SQLState: " + e.getSQLState());
131 | System.out.println("Message: " + e.getMessage());
132 | System.out.println("Vendor: " + e.getErrorCode());
133 | e = e.getNextException();
134 | System.out.println("");
135 | }
136 | }
137 | catch (Exception e)
138 | {
139 | System.out.println("Exception: " + e);
140 | e.printStackTrace ();
141 | }
142 | return TransStore;
143 | }
144 |
145 |
146 | }
--------------------------------------------------------------------------------
/Transfer.jsp:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/Withdraw.jsp:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/afterlogin.jsp:
--------------------------------------------------------------------------------
1 | <%@ page import="java.io.*" %>
2 | <%@ page import="java.util.*" %>
3 | <%@ page import="java.lang.*" %>
4 | <%@ page import="com.mishra.*;" %>
5 |
6 | <%
7 | String Username = new String("");
8 | Username = String.valueOf(request.getAttribute("Username"));
9 | //out.println("Your username is " + Username);
10 |
11 | String Name = new String("");
12 | Name = String.valueOf(request.getAttribute("CustomerName"));
13 | //out.println("Your customername is " + Name);
14 | %>
15 |
16 |
17 |
18 |
22 |
23 |
24 | Welcome to your link page
25 |
40 |
41 |
62 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 | Java Banking Project (Web Version)
2 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/login.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
25 |
26 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------