LabProblem1 (1)
LabProblem1 (1)
Lab Problem #1
Coding requirements:
• Be sure to include Javadoc comments for all public classes and methods as well as comments to
explain your code.
• Your application must:
o use Properties class and a file called database.properties
(as in the Lecture examples)
▪ Be sure to place this file in the src folder … just like in the example.
▪ The connection string, userid and password should match the ones used in our
examples.
o use try-with-resources when instantiating classes that may throw exceptions,
o use ResultSetMetaData to obtain and output the column attributes:
▪ column name
▪ column type (the MySQL type) and
▪ corresponding Java class for the column.
o generate a random year between 1987 and 2020 (inclusive).
▪ Be sure to use java.security.SecureRandom
o Then search the database for all entries which match that year
(this must use a single SQL query). Be sure to:
▪ Use PreparedStatement for the SQL query
1
This example uses data from Ontario’s Data Catalogue. The full dataset is available at:
https://www.ontario.ca/page/order-ontario#section-6
▪ use ResultSet to obtain the results from the search and output the results.
▪ print an appropriate message if no matching entries can be found for that year.
Output:
o All data and metadata should be output in neatly formatted tabular form complete with
column headings. (See the sample output).
Submission: