01: import java.sql.Connection;
02: import java.sql.ResultSet;
03: import java.sql.Statement;
04: import java.sql.SQLException;
05: 
06: /**
07:    A bank consisting of multiple bank accounts.
08: */
09: public class Bank
10: {
11:    /**
12:       Finds a customer with a given number and PIN.
13:       @param conn the database connection
14:       @param customerNumber the customer number
15:       @param pin the personal identification number
16:       @return the matching customer, or null if none found
17:    */
18:    public Customer find(int customerNumber, int pin)
19:       throws SQLException
20:    {  
21:       Customer c = null;
22:       Connection conn = SimpleDataSource.getConnection();
23:       Statement stat = conn.createStatement();
24:       ResultSet result = stat.executeQuery("SELECT *"
25:          + " FROM Customer WHERE Customer_Number = "
26:          + customerNumber);
27:          
28:       if (result.next() && pin == result.getInt("PIN")) 
29:          c = new Customer(customerNumber,
30:             result.getInt("Checking_Account_Number"),
31:             result.getInt("Savings_Account_Number"));
32:       result.close();
33:       stat.close();
34:       conn.close();
35:       return c;
36:    }      
37: }
38: 
39: