previous | start | next

Case Study: A Bank Database

public Customer findCustomer(int customerNumber, int pin)
       throws SQLException
{
   Connection conn = SimpleDataSource.getConnection();
   try
   {
      Customer c = null;
      PreparedStatement stat = conn.prepareStatement(
            "SELECT * FROM BankCustomer WHERE Customer_Number = ?");
      stat.setInt(1, customerNumber);

      ResultSet result = stat.executeQuery();
      if (result.next() && pin == result.getInt("PIN"))
         c = new Customer(customerNumber,
               result.getInt("Checking_Account_Number"),
               result.getInt("Savings_Account_Number"));
      return c;
   }
   finally
   {
      conn.close();
   }
}

previous | start | next