previous | start | next

Case Study: A Bank Database

public double getBalance()
      throws SQLException
{
   Connection conn = SimpleDataSource.getConnection();
   try
   {
      double balance = 0
      PreparedStatement stat = conn.prepareStatement(
            "SELECT Balance FROM Account WHERE Account_Number = ?");
      stat.setInt(1, accountNumber);

      ResultSet result = stat.executeQuery();
      if (result.next())
         balance = result.getDouble(1);
      return balance;
   }
   finally
   {
      conn.close();
   }
}

previous | start | next