previous | start | next

Case Study: A Bank Database

public void deposit(double amount)
      throws SQLException
{
   Connection conn = SimpleDataSource.getConnection();
   try
   {
      PreparedStatement stat = conn.prepareStatement(
            "UPDATE Account"
            + " SET Balance = Balance + ?"
            + " WHERE Account_Number = ?");
      stat.setDouble(1, amount);
      stat.setInt(2, accountNumber);
      stat.executeUpdate();
   }
   finally
   {
      conn.close();
   }
}

previous | start | next