Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part V – Now build the AccountLookupServlet. This servlet should read the input

ID: 3592047 • Letter: P

Question

Part V – Now build the AccountLookupServlet. This servlet should read the input from the previous HTML file and Find the Account’s information from the database, using the Account business class, then display the information back to the “Server Log”. The AccountLookupServlet should be scheduled when the user clicks on the Retrieve button from the “Account. Note: The AccounLookupServlet will not generate any HTML code. That will be done in the next Lab. w Part VI – Lastly, in your “AccountLookupServlet”, put the Account object in the Session. This Account object will be used by a later Servlet to display Account info.

Accountlookup html

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<body>
<center><h1>Account Lookup</h1>
</center>
  
<form>
AcctNo: <input type="text" ><br>
CustomerID: <input type="text" ><br>
Type: <input type="text" ><br>
Balance: <input type="text" ><br>
<input type="submit" value="Lookup">
<input type="reset" value="Clear">
</form>
</body>
</html>

Account.java

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
public class Account {
  

private int AcctNo, Cid;
private double Balance;
private String Type;

public int getAcctNo() {
return AcctNo;
}

public void setAcctNo(int AcctNo) {
this.AcctNo = AcctNo;
}

public int getCid() {
return Cid;
}

public void setCid(int Cid) {
this.Cid = Cid;
}

public double getBalance() {
return Balance;
}

public void setBalance(double Balance) {
this.Balance = Balance;
}

public String getType() {
return Type;
}

public void setType(String Type) {
this.Type = Type;
}

public void selectDB(int acctNo) {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select * from Accounts where AcctNo = " + acctNo);
while (rs.next()) {
setAcctNo(rs.getInt(1));
setCid(rs.getInt(2));
setType(rs.getString(3));
setBalance(rs.getDouble(4));
}
  

} catch (Exception e) {
System.out.println(e.getMessage());
}

}

public void deposit(double amt) {
setBalance(getBalance() + amt);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = con.createStatement();
stmt.executeUpdate("update Accounts set [Balance] ="+getBalance()+" where [AcctNo] = "+getAcctNo());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
  
public void withdraw (double amt) {
setBalance(getBalance() - amt);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = con.createStatement();
stmt.executeUpdate("update Accounts set [Balance] ="+getBalance()+" where [AcctNo] = "+getAcctNo());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void display(){
JOptionPane.showMessageDialog(null,"Balance = "+getBalance());


}


}

Need to be corrected and i need the accountlookupservlet

Explanation / Answer

the code is fixed and changed

Accountlookup html
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<body>
<center><h1>Account Lookup</h1>
</center>
  
<form>
AcctNo: <input type="text" ><br>
CustomerID: <input type="text" ><br>
Type: <input type="text" ><br>
Balance: <input type="text" ><br>
<input type="submit" value="Lookup">
<input type="reset" value="Clear">
</form>
</body>
</html>

Account.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
public class Account {
  
private int AcctNo, Cid;
private double Balance;
private String Type;
public int getAcctNo() {
return AcctNo;
}
public void setAcctNo(int AcctNo) {
this.AcctNo = AcctNo;
}
public int getCid() {
return Cid;
}
public void setCid(int Cid) {
this.Cid = Cid;
}
public double getBalance() {
return Balance;
}
public void setBalance(double Balance) {
this.Balance = Balance;
}
public String getType() {
return Type;
}
public void setType(String Type) {
this.Type = Type;
}
public void selectDB(int acctNo) {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select * from Accounts where AcctNo = " + acctNo);
while (rs.next()) {
setAcctNo(rs.getInt(1));
setCid(rs.getInt(2));
setType(rs.getString(3));
setBalance(rs.getDouble(4));
}
  
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void deposit(double amt) {
setBalance(getBalance() + amt);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = con.createStatement();
stmt.executeUpdate("update Accounts set [Balance] ="+getBalance()+" where [AcctNo] = "+getAcctNo());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
  
public void withdraw (double amt) {
setBalance(getBalance() - amt);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = con.createStatement();
stmt.executeUpdate("update Accounts set [Balance] ="+getBalance()+" where [AcctNo] = "+getAcctNo());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void display(){
JOptionPane.showMessageDialog(null,"Balance = "+getBalance());


}

}