1 / 98

Tutorial 26 – ATM Application Introducing Database Programming and Using Command-Line Arguments

Tutorial 26 – ATM Application Introducing Database Programming and Using Command-Line Arguments.

oswald
Download Presentation

Tutorial 26 – ATM Application Introducing Database Programming and Using Command-Line Arguments

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Tutorial 26 – ATM ApplicationIntroducing Database Programming and Using Command-Line Arguments Outline26.1 IBM Cloudscape Database26.2 Test-Driving the ATM Application 26.3 Planning the ATM Application 26.4 Relational Database Overview: The ATM Database 26.5 SQL 26.6 Using Command-Line Arguments26.7 Creating Database Connections26.8 Programming the Screen Saver Application26.9 Wrap-Up

  2. Objectives • In this tutorial, you will learn to: • Install the Cloudscape database. • Connect to databases. • Create SQL queries. • Retrieve and update information in databases. • Use command-line arguments to pass options to an application as it begins executing.

  3. 26.1 IBM Cloudscape Database • Cloudscape • Pure-Java embedded database management system. • Installing Cloudscape • Type java –jarD:\software\Cloudscape513\cloudscape_eval_513.jar to begin the installation process

  4. 26.1 IBM Cloudscape Database (Cont.) Figure 26.1 Welcome page of Cloudscape installer. (Courtesy of IBM Corporation.)

  5. 26.1 IBM Cloudscape Database (Cont.) Figure 26.2 Options to view the release notes. (Courtesy of IBM Corporation.)

  6. 26.1 IBM Cloudscape Database (Cont.) Figure 26.3 Cloudscape 5.1 release notes. (Courtesy of IBM Corporation.)

  7. 26.1 IBM Cloudscape Database (Cont.) Figure 26.4 Accepting the Cloudscape license agreement. (Courtesy of IBM Corporation.)

  8. 26.1 IBM Cloudscape Database (Cont.) Figure 26.5 Choosing the Cloudscape installation directory. (Courtesy of IBM Corporation.)

  9. 26.1 IBM Cloudscape Database (Cont.) Figure 26.6 Choosing the default setup type. (Courtesy of IBM Corporation.)

  10. 26.1 IBM Cloudscape Database (Cont.) Figure 26.7 Confirming the location of the Cloudscape installation. (Courtesy of IBM Corporation.)

  11. 26.1 IBM Cloudscape Database (Cont.) Figure 26.8 Cloudscape installation process dialog. (Courtesy of IBM Corporation.)

  12. 26.1 IBM Cloudscape Database (Cont.) Figure 26.9 Completing the Cloudscape installation. (Courtesy of IBM Corporation.)

  13. 26.1 IBM Cloudscape Database (Cont.) Figure 26.10 Exiting the installer wizard. (Courtesy of IBM Corporation.)

  14. 26.2 Test-Driving the ATM Application

  15. 26.2 Test-Driving the ATM Application (Cont.) • Setting the CLASSPATH environment variable • Set this variable so Java can interact with Cloudscape • Running the ATM application • Type java ATM com.ibm.db2j.jdbc.DB2jDriverjdbc:db2j:ATM in the CommandPrompt window • Command-line arguments

  16. Result of running setCP.bat 26.2 Test-Driving the ATM Application (Cont.) Figure 26.11 Setting the CLASSPATH environment variable.

  17. 26.2 Test-Driving the ATM Application (Cont.) Figure 26.12 Passing command-line arguments to the ATM application.

  18. Displays instructions and messages to the user Keypad for entering a PIN or a withdrawal amount All JButtons are disabled initially JComboBox that displays account numbers 26.2 Test-Driving the ATM Application (Cont.) Figure 26.13 ATM application.

  19. Prompt the user to provide a PIN Keypad JButtons are enabled DoneJButton is enabled JComboBox is disabled 26.2 Test-Driving the ATM Application (Cont.) Figure 26.14 Selecting an account number from the JComboBox.

  20. An asterisk is displayed here for each keypad JButton pressed for the PIN EnterJButton is enabled 26.2 Test-Driving the ATM Application (Cont.) Figure 26.15 Entering the PIN for the selected account.

  21. Welcome message displays in JTextArea when the user enters the correct PIN EnterJButton is disabled BalanceJButton is enabled Keypad JButtons are disabled WithdrawJButton is enabled 26.2 Test-Driving the ATM Application (Cont.) Figure 26.16 ATM displaying welcome message.

  22. 26.2 Test-Driving the ATM Application (Cont.) • Confirming the use of the database • Click the BalanceJButton to check the account balance • Withdrawing money • Click the WithdrawalJButton • Input an amount to withdraw and click the EnterJButton • Click the BalanceJButton again • Notice that the balance reflects the withdrawal you performed

  23. Balance displays in JTextArea 26.2 Test-Driving the ATM Application (Cont.) Figure 26.17 Viewing the account balance.

  24. Ask the user to enter a withdrawal amount BalanceJButton is disabled Keypad JButtons are enabled WithdrawJButton is disabled 26.2 Test-Driving the ATM Application (Cont.) Figure 26.18 Withdrawing money from the account.

  25. Display the withdrawal amount BalanceJButton is enabled Keypad JButtons are disabled WithdrawJButton is enabled 26.2 Test-Driving the ATM Application (Cont.) Figure 26.19 ATM application displaying the withdrawal amount.

  26. Display new balance 26.2 Test-Driving the ATM Application (Cont.) Figure 26.20 Checking new balance.

  27. Displays instructions and messages to the user Keypad JButtons are disabled JButtons are disabled JComboBox is enabled 26.2 Test-Driving the ATM Application (Cont.) Figure 26.21 ATM application ready for next customer.

  28. 26.3 Planning the ATM Application When the user selects an account number from the JComboBox Disable the JComboBox Prompt the user to enter a PIN Clear the JTextField for the PIN Enable the keypad Jbuttons Enable the Done JButton When the user enters the PIN Enable the Enter Jbutton Append the number to the PIN

  29. 26.3 Planning the ATM Application (Cont.) When the user clicks the Enter JButton to submit the PIN Search the database for the account number’s corresponding account information If the user provided a correct PIN Clear the JTextField Disable the Enter Jbutton Disable the keypad Jbuttons Enable the Balance and Withdraw Jbuttons Display the status to the user Else Clear the JTextField Prompt the user to enter a valid PIN When the user clicks the Balance Jbutton Display the balance

  30. 26.3 Planning the ATM Application (Cont.) When the user clicks the Withdraw Jbutton Disable the Balance and Withdraw Jbuttons Enable the keypad Jbuttons Prompt the user to enter the withdrawal amount When the user clicks the Enter JButton to submit the withdrawal amount Disable the Enter Jbutton Disable the keypad Jbuttons Process the withdrawal and display the withdrawal amount Clear the withdrawal amount in the JTextField Enable the Balance and Withdraw JButtons When the user clicks the Done Jbutton Disable the keypad Jbuttons Disable the Enter, Balance, Withdraw and Done Jbuttons Enable the JComboBox Display instructions for the next customer in the JTextArea

  31. 26.3 Planning the ATM Application (Cont.)

  32. 26.3 Planning the ATM Application (Cont.)

  33. 26.3 Planning the ATM Application (Cont.)

  34. 26.3 Planning the ATM Application (Cont.)

  35. 26.3 Planning the ATM Application (Cont.)

  36. 26.3 Planning the ATM Application (Cont.)

  37. 26.4 Relational Database Overview: The ATM Database • Database • Organized collection of data • Database management system (DBMS) • enables applications to access and store data without worrying about how the data is organized

  38. 26.4 Relational Database Overview: The ATM Database (Cont.) • Relational database • Stores data in tables • Tables store data in rows and columns • Primary key - field that contains unique values used to distinguish records from one another • Structured Query Language • Perform queries • Manipulate data

  39. 26.4 Relational Database Overview: The ATM Database (Cont.)

  40. 26.5 SQL • Basic SELECT Query • Selects rows and columns from a table • Performed by SELECT • Basic form: SELECT * FROMTableName • * indicates all columns from TableName will be selected • * can be replaced by comma-separated list of columns to retrieve • e.g. SELECT accountNumber FROMaccountInformation • FROM indicates the table from which to retrieve data

  41. 26.5 SQL (Cont.) • SELECT accountNumber, firstName FROM accountInformation

  42. 26.5 SQL (Cont.) • WHERE Clause • Specify the selection criteria for a query • Only rows that satisfy the criteria will be selected • Combined with a SELECT statement • General form: • SELECTcolumnName1, columnName1, … FROMTableNameWHEREcriteria • Example • SELECT pin, firstName, balanceAmount FROM accountInformation WHERE accountNumber = ’12548693’

  43. 26.5 SQL (Cont.)

  44. 26.5 SQL (Cont.) • UPDATE Statement • Modify data in a table • Basic form: • UPDATETableName SETcolumnName1=value1,columnName2=value2 … WHEREcriteria • TableName specifies table to update • SET keyword is followed by list of column name/value pairs • WHERE clause determines which rows to update • Example • UPDATE accountInformation SET balanceAmount = 1000 WHERE accountNumber = ‘12548693

  45. 26.5 SQL (Cont.)

  46. 26.6 Using Command-Line Arguments • main method • Command line arguments • Passed to main as String array args • Length of args • Standard output object • System.out • Display text in the CommandPrompt window

  47. Start the main method declaration Check the number of command-line arguments Get command-line arguments Pass command-line arguments to the constructor Display a line of text that indicates the syntax to run the application 26.6 Using Command-Line Arguments (Cont.) Figure 26.27 Viewing the main method.

  48. 26.7 Creating Database Connections • JDBC API • Communicate and manipulate databases • JDBC Driver • Provided by a DMNS vendor • Enable Java applications to access a particular database

  49. Importing the java.sql package 26.7 Creating Database Connections (Cont.) Figure 26.28 Importing the java.sql package . • java.sql package • Perform database processing

  50. 26.7 Creating Database Connections (Cont.) • Connection object • Manages connection between Java application and database • Allows applications to create SQL statements • Statement object • Enables applications to execute SQL statements • ResultSetobject • Returned by executing a query • Contain rows and columns selected • Rows of table returned in sequence • One ResultSet per Statement

More Related