Java and JDBC Programming
In this exercise you will do some Java and JDBC programming practice. You can use the sample file TestJDBC.java as the template. Your tasks are described as follows:
-
Study the sample code TestJDBC.java and notice how it is organized.
-
Compile your Java source code with:
javac -C TestJDBC.java
-
Run the executable file with:
java TestJDBC username password
-
Load the catalog.sql database in Oracle and create a new file CatalogJDBC.java in which you setup the code for a program that creates requires as input your username and password and which connects to the Oracle database.
-
Create a method getPartSuppliers() that prompts for a partname ('pname') using a the normal Statement. The method should return the names of the suppliers, cost and color for every part in the catalog having this partname.
-
Create a method updateCost() that can update the cost of a part using a PreparedStatement. The method should prompt for the part's pid and the new price. Make sure to include proper error handling for corrupted input.
-
Create a method showStructure() that displays the structure of the tables Suppliers, Parts, and Catalog using the getMetaData() method.
-
Construct your code such that the command line run looks as follows:
java CatalogJDBC username password command
The string command should be either getsuppliers, updatecost or showdb. If getsuppliers, then the method getPartSuppliers() should be executed, if updatecost, then the method getPartSuppliers() should be executed, and if getmetadata, then the method showStructure() should be executed.
