Write a Java program that will connect to the hotel reservations database you
created in the previous assignment. The program should provide a method
named displayQuery that will accept a query (String) as a parameter
and will display the query results formatted so all columns are aligned. Each
column should be labeled at the top with the heading name provided in the
query result. The columns should be displayed at precisely the width of the
longest data value plus a single space.
To accomplish this you will need to make two passes through the ResultSet.
In the first pass you need to figure out the widest string to be display in each
column. On the second pass you need to pad output with spaces to ensure that
all items have the same width. REMEMBER: The column name may be the widest
As with the in-class assignment you should store your credentials in a file
named dbconnect.txt rather than in the Java program itself.
Access to port 5432 on the csci server is open, but HSU's firewalls
prevent off-campus access. You can work on this assignment in a couple of
- Do your work on campus (HSUWireless or plugged in to the wall in
- Do your work by connecting to the csci.hsutx.edu server using an
ssh client. This will require you to learn a text-only editor (such
as vim or nano). If you have not worked in this way you need
to leave a couple of days just for the purpose of getting proficient in
working with files in that environment. This document can help you get
To determine column header names and other useful metadata about the query result
you will make use of a ResultSetMetaData object.
Since you will be making two passes through the ResultSet you need to make
the result set scrollable. See the paragraphs of documentation at the top of
information on how to do that.
I recommend (but don't require) that you use an object-oriented design for
this program. In particular it would be helpful to have a class to manage
a database connection whose constructor will connect to the database. Then the
connection object (which will be a classwide attribute) will be available to
your displayQuery() method without have to re-establish a connection to
the database every time a query is issued.
Combine all of your source files (including the dbconnect.txt file) into a
single zipped archive called hw8.zip and upload into Canvas before the due