Week 10 - Accessing a Database in Java

  1. Create a new mySQL database on igor and and add a table to your database and insert some rows into your database.
  2. Adapt seb1.java so it works with your database. It should print out the table of your database.
  3. Adapt seb2.java so it inserts a row into your table.
  4. Adapt seb2.java so it allows the user to enter new rows at the command line.
  5. Create a table with two columns a name and an age. Write a program which works out the average age of all the people in the table.
  6. Write a program which sorts the table into descending order of age.

  7. You cannot access the mySQL server on igor on from outside as it is behind the firewall. Create a copy of the above database on igor (read this. to find out how to do it).

  8. (Easy Assignment) Create a Postgres or a MySQL database with a table with two fields: Name (String) and age (int) and write a program that prints out the average age of all people in the database. (You are not allowed to use the SQL 'average' or 'sum' functions.)

  9. (Hard Assignment)
    1. Create a Postgres or a MySQL database with a table with two fields: Name (String) and age (int) and write a program that converts the table to TreeMap <String,Integer>, add a new pair to the map and then use Object serialization to store the TreeMap in a file.

    2. Write another program which takes the file converts it to a TreeMap <String,Integer> and updates the table with the contents of the TreeMap.

s.danicic@gold.ac.uk
Sebastian Danicic BSc MSc PhD (Reader in Computer Science)
Dept of Computing, Goldsmiths, University of London, London SE14 6NW
Last updated 2015-09-04