Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help with this please! We need to use Java to code this assignment which invlolv

ID: 3704894 • Letter: H

Question

Help with this please!

We need to use Java to code this assignment which invlolves processing SQL code in Java. I'm currently using the Java JDBC to program this.

Exercises

All operations will be performed on the Mall database.

1. [5 pts] After each of the query operations listed here, display relevant results. When executing the user’s currently built SQL statement, display all the tuples returned.

2. Provide the user with a menu system that facilitates the following operations.

• [5 pts] Entering a complete SQL command. Note, this would only be useful to users who know how to write SQL statements. Inexperienced users would leverage the other options.

• [5 pts] Selecting a table from the list of relations.

• [5 pts] Once a table has been selected, selecting columns from the table.

• [5 pts] Executing the currently built SQL statement as a query from the table/column(s) selected.

Explanation / Answer

1.

public static void viewTable(Connection con, String dbName)
throws SQLException {

Statement stmt = null;
String query = "select COF_NAME, SUP_ID, PRICE, " +
"SALES, TOTAL " +
"from " + dbName + "Mall";
try {
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");
int supplierID = rs.getInt("SUP_ID");
float price = rs.getFloat("PRICE");
int sales = rs.getInt("SALES");
int total = rs.getInt("TOTAL");
System.out.println(coffeeName + " " + supplierID +
" " + price + " " + sales +
" " + total);
}
} catch (SQLException e ) {
JDBCTutorialUtilities.printSQLException(e);
} finally {
if (stmt != null) { stmt.close(); }
}
}

2.Query to select only ITEM, PRICE, columns:

-- selecting only certain columns is called a "projection".

SELECT ITEM, PRICE FROM MENU;

ID ITEM PRICE

1 MTJ 25.00

4 AGR 34.55

6 DAL 120

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote