2.4 Bases de Dados Estudo de Caso. Caso: Caixa Eletrônico Caixa Eletrônico com acesso à Base de Dados; Cada cliente possui:  Um número de cliente  Uma.

Slides:



Advertisements
Similar presentations
1 Radio Maria World. 2 Postazioni Transmitter locations.
Advertisements

EcoTherm Plus WGB-K 20 E 4,5 – 20 kW.
Números.
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.
AGVISE Laboratories %Zone or Grid Samples – Northwood laboratory
Trend for Precision Soil Testing % Zone or Grid Samples Tested compared to Total Samples.
SKELETAL QUIZ 3.
PDAs Accept Context-Free Languages
Reflection nurulquran.com.
1
EuroCondens SGB E.
Worksheets.
Slide 1Fig 26-CO, p.795. Slide 2Fig 26-1, p.796 Slide 3Fig 26-2, p.797.
Slide 1Fig 25-CO, p.762. Slide 2Fig 25-1, p.765 Slide 3Fig 25-2, p.765.
& dding ubtracting ractions.
Sequential Logic Design
Addition and Subtraction Equations
David Burdett May 11, 2004 Package Binding for WS CDL.
Western Public Lands Grazing: The Real Costs Explore, enjoy and protect the planet Forest Guardians Jonathan Proctor.
Add Governors Discretionary (1G) Grants Chapter 6.
CALENDAR.
CHAPTER 18 The Ankle and Lower Leg
Summative Math Test Algebra (28%) Geometry (29%)
ASCII stands for American Standard Code for Information Interchange
The 5S numbers game..
突破信息检索壁垒 -SciFinder Scholar 介绍
A Fractional Order (Proportional and Derivative) Motion Controller Design for A Class of Second-order Systems Center for Self-Organizing Intelligent.
Break Time Remaining 10:00.
The basics for simulations
A sample problem. The cash in bank account for J. B. Lindsay Co. at May 31 of the current year indicated a balance of $14, after both the cash receipts.
PP Test Review Sections 6-1 to 6-6
MM4A6c: Apply the law of sines and the law of cosines.
Figure 3–1 Standard logic symbols for the inverter (ANSI/IEEE Std
TCCI Barometer March “Establishing a reliable tool for monitoring the financial, business and social activity in the Prefecture of Thessaloniki”
1 Prediction of electrical energy by photovoltaic devices in urban situations By. R.C. Ott July 2011.
Dynamic Access Control the file server, reimagined Presented by Mark on twitter 1 contents copyright 2013 Mark Minasi.
TCCI Barometer March “Establishing a reliable tool for monitoring the financial, business and social activity in the Prefecture of Thessaloniki”
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Progressive Aerobic Cardiovascular Endurance Run
Biology 2 Plant Kingdom Identification Test Review.
Visual Highway Data Select a highway below... NORTH SOUTH Salisbury Southern Maryland Eastern Shore.
MaK_Full ahead loaded 1 Alarm Page Directory (F11)
Facebook Pages 101: Your Organization’s Foothold on the Social Web A Volunteer Leader Webinar Sponsored by CACO December 1, 2010 Andrew Gossen, Senior.
TCCI Barometer September “Establishing a reliable tool for monitoring the financial, business and social activity in the Prefecture of Thessaloniki”
When you see… Find the zeros You think….
2011 WINNISQUAM COMMUNITY SURVEY YOUTH RISK BEHAVIOR GRADES 9-12 STUDENTS=1021.
Before Between After.
2011 FRANKLIN COMMUNITY SURVEY YOUTH RISK BEHAVIOR GRADES 9-12 STUDENTS=332.
2.10% more children born Die 0.2 years sooner Spend 95.53% less money on health care No class divide 60.84% less electricity 84.40% less oil.
Subtraction: Adding UP
: 3 00.
5 minutes.
Numeracy Resources for KS2
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
Static Equilibrium; Elasticity and Fracture
Converting a Fraction to %
Resistência dos Materiais, 5ª ed.
Clock will move after 1 minute
& dding ubtracting ractions.
Select a time to count down from the clock above
A Data Warehouse Mining Tool Stephen Turner Chris Frala
1 Dr. Scott Schaefer Least Squares Curves, Rational Representations, Splines and Continuity.
1 Non Deterministic Automata. 2 Alphabet = Nondeterministic Finite Accepter (NFA)
Introduction Embedded Universal Tools and Online Features 2.
úkol = A 77 B 72 C 67 D = A 77 B 72 C 67 D 79.
Schutzvermerk nach DIN 34 beachten 05/04/15 Seite 1 Training EPAM and CANopen Basic Solution: Password * * Level 1 Level 2 * Level 3 Password2 IP-Adr.
Presentation transcript:

2.4 Bases de Dados Estudo de Caso

Caso: Caixa Eletrônico Caixa Eletrônico com acesso à Base de Dados; Cada cliente possui:  Um número de cliente  Uma senha  Uma conta corrente  Uma conta poupança Os dados serão armazenados em duas tabelas;

Tabelas do Caixa Eletrônico

Estudo de Caso A classe Banco precisa se conectar à base para encontrar os cliente existentes; Criar um método EncontraCliente  Se conecta a base de dados  Seleciona um cliente apartir de um número  Verifica a senha do cliente  Cria um objeto cliente apartir dos dados vindos do banco; SELECT * FROM BankCustomer WHERE Customer_Number =...

Estudo de Caso A classe ContaBancaria terá seus métodos alterados; O método getSaldo deve pegar o saldo da base de dados; Os métodos saque e deposito devem atualizar a base de dados;

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(); }

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(); }

File Bank.java 01: import java.sql.Connection; 02: import java.sql.ResultSet; 03: import java.sql.PreparedStatement; 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. customerNumber the customer number pin the personal identification number the matching customer, or null if none found 16: */ Continued

File Bank.java 17: public Customer findCustomer(int customerNumber, int pin) 18: throws SQLException 19: { 20: Connection conn = SimpleDataSource.getConnection(); 21: try 22: { 23: Customer c = null; 24: PreparedStatement stat = conn.prepareStatement( 25: "SELECT * FROM BankCustomer WHERE Customer_Number = ?"); 26: stat.setInt(1, customerNumber); 27: 28: ResultSet result = stat.executeQuery(); 29: if (result.next() && pin == result.getInt("PIN")) 30: c = new Customer(customerNumber, 31: result.getInt("Checking_Account_Number"), 32: result.getInt("Savings_Account_Number")); 33: return c; Continued

File Bank.java 34: } 35: finally 36: { 37: conn.close(); 38: } 39: } 40: } 41: 42:

File BankAccount.java 01: import java.sql.Connection; 02: import java.sql.ResultSet; 03: import java.sql.PreparedStatement; 04: import java.sql.SQLException; 05: 06: /** 07: A bank account has a balance that can be changed by 08: deposits and withdrawals. 09: */ 10: public class BankAccount 11: { 12: /** 13: Constructs a bank account with a given balance. anAccountNumber the account number 15: */ 16: public BankAccount(int anAccountNumber) 17: { Continued

File BankAccount.java 18: accountNumber = anAccountNumber; 19: } 20: 21: /** 22: Deposits money into a bank account. amount the amount to deposit 24: */ 25: public void deposit(double amount) 26: throws SQLException 27: { 28: Connection conn = SimpleDataSource.getConnection(); 29: try 30: { 31: PreparedStatement stat = conn.prepareStatement( 32: "UPDATE Account" 33: + " SET Balance = Balance + ?" 34: + " WHERE Account_Number = ?"); 35: stat.setDouble(1, amount); Continued

File BankAccount.java 36: stat.setInt(2, accountNumber); 37: stat.executeUpdate(); 38: } 39: finally 40: { 41: conn.close(); 42: } 43: } 44: 45: /** 46: Withdraws money from a bank account. amount the amount to withdraw 48: */ 49: public void withdraw(double amount) 50: throws SQLException 51: { 52: Connection conn = SimpleDataSource.getConnection(); Continued

File BankAccount.java 53: try 54: { 55: PreparedStatement stat = conn.prepareStatement( 56: "UPDATE Account" 57: + " SET Balance = Balance - ?" 58: + " WHERE Account_Number = ?"); 59: stat.setDouble(1, amount); 60: stat.setInt(2, accountNumber); 61: stat.executeUpdate(); 62: } 63: finally 64: { 65: conn.close(); 66: } 67: } 68: Continued

File BankAccount.java 69: /** 70: Gets the balance of a bank account. the account balance 72: */ 73: public double getBalance() 74: throws SQLException 75: { 76: Connection conn = SimpleDataSource.getConnection(); 77: try 78: { 79: double balance = 0; 80: PreparedStatement stat = conn.prepareStatement( 81: "SELECT Balance FROM Account WHERE Account_Number = ?"); 82: stat.setInt(1, accountNumber); 83: ResultSet result = stat.executeQuery(); 84: if (result.next()) 85: balance = result.getDouble(1); Continued

File BankAccount.java 86: return balance; 87: } 88: finally 89: { 90: conn.close(); 91: } 92: } 93: 94: private int accountNumber; 95: } 96: