Transfer Code Help Needed for Banking Program!

M

mrfurley15

Hi guys, I came here before requesting help. Hope you all remember.
Anyway, here is my jsp/java files for this banking system. I'm trying
to write code to make a transfer between two accounts, using From and
To, and displaying Date & Time, Transferred From, To, FromAccountID, To
AccountID, New Avil, New Bal. Please help!!

Transfer.jsp

<html>
<head>
<title>TRANSFER</title>
</head>
<body>
<jsp:include page="menu.html" flush="true" />
<jsp:useBean id="customer" scope="session" class="Bank.Customer" />
<table cellpadding="0" cellspacing="0" border="0" width="569"><tr><td
class="heading" align="left" colspan="3">
<form METHOD="POST" ACTION="TransferControl">
<jsp:getProperty name="customer" property="transfer" />
<tr><td><input type="Submit" value=Transfer></td></tr>
</table>
</body>
</html>

------------------------------------------------------------

TransferConfirmation.jsp

<html>
<head>
<title>TRANSFER RESULTS</title>
</head>
<body>
<jsp:include page="menu.html" flush="true" />
<h3> Transfer Not Implemented Yet</h3><br>
<br><h4> Use the menu to continue</h4><br>
<br>
<table cellpadding="2" cellspacing="2" border="1" style="text-align:
left; width: 50%;">

<tr><td>Date</td><td>Transferred From</td><td>Transferred
To</td></tr><tr>
<td>test.getToday()</td><td>FromAccount</td><td>"ToAccount</td></tr><tr></tr><tr>
<td>New
Available</td><td>test.getnewFromAvail()</td><td>test.getnewToAvail()</td></tr>
<td>New
Balance</td><td>test.getnewFromBal()</td><td>test.getnewToBal()</td></tr>
</table>
</body>
</html>

_____________________________________________

TransferControl.java

package Bank;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import Bank.DBI;
import Bank.Customer;
import Bank.Control;

public class TransferControl extends Bank.Control
{
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
String fromAccount = request.getParameter("FromAccount");
String toAccount = request.getParameter("ToAccount");
String amount = request.getParameter("Amount");
HttpSession session = request.getSession();

Bank.Customer custbean =
(Bank.Customer)session.getAttribute("customer");
boolean proceed = this.transfer(custbean);

if(proceed) {
/* Transfer Succeded */
gotoPage("/TransferConfirmation.jsp", request,
response);
}
else {
/* Transfer Failed */
gotoPage("/Transfer.jsp", request, response);
}
}

private boolean transfer(Bank.Customer bean) throws
ServletException {
return true;
}

}

________________________________________________________-

DBI.java

package Bank;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Vector;

public class DBI {
// All Bank database methods are here
Connection conn = null;
String[] accountFields = {"AccountID", "Balance", "Available",
"Type"};

public DBI() throws NamingException, SQLException {
}

public boolean connect() throws NamingException, SQLException {
// Connect to the Bank database
// Using the Tomcat Server.xml Context to locate the data
Context initCtx = new InitialContext();
Context envCtx =
(Context)initCtx.lookup("java:comp/env");
if(envCtx == null ) throw new NamingException("Boom -
No Context");
// Use jdbc to connect with sql statements
DataSource ds =
(DataSource)envCtx.lookup("jdbc/TestDB");
//if ds is not null, the datasource was established
(Tomcat connection pool open with database
if(ds!=null) {
// Get a connection from the Tomcat database
connection pool with Bank server
conn = ds.getConnection();
// If we get the connection ...
if(conn != null) { return true; }
}
return false;
}
public ResultSet execQuery(String str) throws SQLException {
// Build a jdbc statement from an SQL query string
Statement stmt = conn.createStatement();
// Execute the query and fetch the ResultSet from the
database
ResultSet rst = stmt.executeQuery(str);
return rst;
}

public boolean checkCustPin(String custID, String pin) throws
SQLException {
// rst gets the results of the Select query looking for custID
and pin
ResultSet rst = this.execQuery("SELECT CustomerId,
Firstname, Lastname, PIN FROM Customer WHERE CustomerId = "+custID+"
and PIN = "+pin);
// Go to first row of the ResultSet; if there are no rows,
customerID and pin do not match
boolean result=(rst.first());
return result;
}

public String[] getCustNames(String custID) throws SQLException
{
// Retrive the Firstname and Lastname fields of the custID
String[] result = new String[2];
ResultSet rst = this.execQuery("SELECT CustomerId,
Firstname, Lastname, PIN FROM Customer WHERE CustomerId = "+custID);
if(rst.first()) {
result[0] = rst.getString("Firstname");
result[1] = rst.getString("Lastname");
}
return result;
}

public Vector getAccounts(String customerID) throws
SQLException {
Vector accounts = new Vector(10);
// Get a vector of all accounts that belong to this
customer
ResultSet rst = this.execQuery("SELECT AccountId FROM
UserAccounts WHERE CustomerId = "+customerID);
if(rst.first()) {
do {

accounts.add(rst.getString(this.accountFields[0]));
} while(rst.next());
}
return(accounts);
}

public String[] getAccountInfo(String accountID) throws
SQLException {
String[] info = new String[4];
info[0] = accountID;
// Get the Account info array for an account
ResultSet rst = this.execQuery("SELECT Balance,
Available, Type FROM Accounts WHERE AccountId= "+accountID);
for(int i=1;i<4;i++) {
if(rst.first()) {

info=rst.getString(this.accountFields);
}
}
return(info);
}

public String[][] getAllAccountInfo(String customerID) throws
SQLException {
// Get all account info for all accounts for this
customerID
String[][] accountInfo = new String[10][4];
// Get a vector of string AccountIds of this customer
Vector accounts = this.getAccounts(customerID);
for(int i=0;i<accounts.size();i++) {
// Get the array of AccountInfo fields for each AccountId
accountInfo =
this.getAccountInfo((String)accounts.get(i));
}
if(accountInfo[0][0] == null) throw new
SQLException("No Accounts Found");
return(accountInfo);
}

}

---------------------------------------------------------------------

Control.Java

package Bank;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.sql.*;
import java.sql.*;
import Bank.DBI;
import Bank.Customer;

public class Control extends HttpServlet
{
//Control begins the Bank application and transfers to Login.jsp
// All Bank servlets extend this one

protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{ //create new session from Tomcat
HttpSession session = request.getSession(true);
//create new bean
Bank.Customer custbean = new Bank.Customer();
custbean.setError("");
//bind bean to session & name it "customer"
session.setAttribute("customer", custbean);
gotoPage("/Login.jsp", request, response);
}

protected void gotoPage(String address,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException

{
// Use the HttpRequest Dispatcher to forward an HTTPrequest and
go to that page address
RequestDispatcher dispatcher =
this.getServletContext().getRequestDispatcher(address);
dispatcher.forward(request, response);
}

public boolean testNum(String instring)
{
char[] amountArray = instring.toCharArray();
int decimals=0;
// Nested numeric tests of instring amount, ok as integer or
decimal
for(int i = 0; i < amountArray.length; i++) {
if(!((Character.isDigit(amountArray)))) {
if(amountArray=='.') {
decimals++;
if(decimals >1) return false;
}
else return false;
}
}
return true;
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top