UWA Logo
  Faculty Home | School Home    
           
Home
About the School
Contact and People
Future Undergraduate Students
Prospective Postgraduates
Current Students
Current Postgraduates
Research
IT News
Awards
Industry Links and Prizes
School and IT Information
Other
Internal Information

Lab Five

Java Database Connectivity

In this lab we'll connect a Java client program to a MySQL database, extract and process the resulting data.

There is just one task that your program must do:

Specification

Write a Java client program that takes a single command-line argument which is the name of one of the world regions in the "world" database.

The output of the program should be

  • The total population of all the countries in that region, and
  • A list of the five most heavily populated countries in that region, along with the percentages of the region's population living in that country, and
  • [optional] a graphical representation of this data as a bar-chart.

You may use any proportion of SQL and Java that you like to produce the results.

Hints and Suggestions

  • You will need to read the lecture notes "JDBC I" before even attempting this lab.
  • The driver for MySQL is the file "C:/Program Files/Java/jre.1.6.0_03/lib/ext/mysql-connector-java-5.1.5-bin.jar ".
  • You may choose to use the command-line environment for this project, or BlueJ, or Eclipse according to your comfort level with these tools. If you use BlueJ or Eclipse then you need to inform the IDE where to locate the .jar file containing the driver classes. In BlueJ this is done on the "Libraries" tag of the "Preferences" dialog. For a program of this small size, I would recommend using BlueJ.
  • If you choose the graphical display option, then you can either build a GUI yourself (via JFrames, JPanels etc) or you can use the SimpleCanvas class which provides a very simple "draw only" window (the SimpleCanvas class can be downloaded from a link on the CITS1200 laboratories.)

Sample Output

Suppose that your program is called "RegionViewer.java".

Then executing from the command line as follows:

java RegionViewer Middle East

should produce output similar to

The region Middle East

Total Population: 188,380,700

Top Five Countries

Turkey 66,591,000 (35.35%)
Iraq 23,115,000 (12.27%)
Saudi Arabia 21,607,000 (11.47%)
Yemen 18,112,000 (9.61%)
Syria 16,125,000 (8.56%)

while

java RegionViewer South America

should produce output similar to

The region South America

Total Population: 345,780,000

Top Five Countries

Brazil 170,115,000 (49.2%)
Colombia 42,321,000 (12.24%)
Argentina 37,032,000 (10.71%)
Peru 25,662,000 (7.42%)
Venezuela 24,170,000 (6.99%)

Do not worry too much about how neat the output looks; the main point here is to go through all the steps required to successfully connect a Java program to a DBMS and then perform some processing of the results.

Top of Page