Question
1. Above is the question 2. Below is the main.java import java.sql.*; public class Main { public static void main(String[] args) { try { //
1. Above is the question
2. Below is the main.java
import java.sql.*; public class Main { public static void main(String[] args) { try { // Connect to the library_db database, via the jdbc:mysql: channel on localhost (this PC) // Use username "otheruser", password "swordfish". Connection connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/library_db?useSSL=false", "otheruser", "swordfish" ); // Create a direct line to the database for running our queries Statement statement = connection.createStatement(); ResultSet results; int rowsAffected; // Set up finished, do some stuff: // executeQuery: runs a SELECT statement and returns the results. results = statement.executeQuery("SELECT title, qty FROM books"); // Loop over the results, printing them all. while (results.next()) { System.out.println(results.getString("title") + ", " +results.getInt("qty")); } // Add a new book: rowsAffected = statement.executeUpdate( "INSERT INTO books VALUES (3001, 'Programming 101', 'Jane Doe', 1)" ); System.out.println("Query complete, " + rowsAffected + " rows added."); printAllFromTable(statement); // Change a book: rowsAffected = statement.executeUpdate( "UPDATE books SET qty=500 WHERE id=1001" ); System.out.println("Query complete, " + rowsAffected + " rows updated."); printAllFromTable(statement); // Clear a book: rowsAffected = statement.executeUpdate( "DELETE FROM books WHERE id=3001" ); System.out.println("Query complete, " + rowsAffected + " rows removed."); printAllFromTable(statement); // Close up our connections results.close(); statement.close(); connection.close(); } catch (SQLException e) { // We only want to catch a SQLException - anything else is off-limits for now. e.printStackTrace(); } } /** * Method printing all values in all rows. * Takes a statement to try to avoid spreading DB access too far. * * @param a statement on an existing connection * @throws SQLException */ public static void printAllFromTable(Statement statement) throws SQLException{ ResultSet results = statement.executeQuery("SELECT id, title, author, qty FROM books"); while (results.next()) { System.out.println( results.getInt("id") + ", " + results.getString("title") + ", " + results.getString("author") + ", " + results.getInt("qty") ); } } }
Using the MySQL client: Create a new table in the dogs_ab database called student (id int, name varchar(50), grade float); Insert the following 3 new rows into the student table: Select all records with a grade between 60 and 80 . Change Carl Davis's grade to 65. Delete Dennis Fredrickson's row. Change the grade of all people with an id greater than 55 to 80 . After executing each instruction given above, take a screenshot of your console and place it in a document to send in for review. Number your screenshots 1 to 5 in order of execution. Modify the Java program Main.java to set the qty for Introduction to Java to 0. Modify the Java program Main.java to delete all books with id >8000; and insert: (8001, 'Java ABC', 'Kevin Jones', 3) and (8002, 'Java XYZ', 'Kevin Jones', 5)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started