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

Hi, There are 2 parts to my question: 1. Create a new Derby database similar to

ID: 3682385 • Letter: H

Question

Hi,

There are 2 parts to my question:

1. Create a new Derby database similar to the one downloaded in step 1 (only the inventory table is required). Insert at least three rows of data in the inventory table. Create a new class (similar to ExecuteExample, named EE2), that does the same actions as ExecuteExample, but with the Derby database. The code should have minimal changes (if any). Include a screen shot of the updated database structure.

2. Create a new class that requests data from the inventory table for the Derby database. The user will enter a product ID and the program will return a product name. Include a screen shot of the contents of the inventory table.

Here is the ExecuteExample:

package JDBC;
import java.util.*;
import java.io.*;
import java.sql.*;

public class ExecuteExample
{
public static void main (String args[])
{
String className=null;
String url=null;
String user = null;
String password = null;
  
try
{
ResourceBundle resources;
InputStream in = null;
ResourceBundle newResources;

in = ClassLoader.getSystemResourceAsStream("db.properties");

resources = new PropertyResourceBundle(in);

in.close();

className = resources.getString("jdbc.driver");
url = resources.getString("jdbc.url");
System.out.println(url);
user = resources.getString("jdbc.user");
password = resources.getString("jdbc.password");
}
catch (Exception exp)
{
System.out.println("Couldn't load resources." + exp);
System.exit(-1);
}
  
try
{
Class.forName(className);
}
catch (Exception e)
{
System.out.println("Failed to load driver.");
return;
}
  
try
{
Connection con = DriverManager.getConnection(url,user,password);   
  
Statement stmt = con.createStatement();

stmt.execute("CREATE TABLE SalesHistory4" +
"(ProductID int," +
" Price int, " +
"TrnsDate varchar(255), "+
"primary key (price), " + //")");
"foreign key (ProductID) references Inventory(ProductID))");
  
System.out.println("Created Sales History table");
  
stmt.close();
  
con.close();
}
catch (Exception e)
{
System.out.println(e);
}
}
}

Here is the Inverntory table:

Please include the screen shot as well.

Thank you so much!

Inventory ReorderLe. Discontim LeadTime Quantity 12 Price ProductID ProductNa· ProductDe Category!. 15 17 19 Blue potato nice textur Wax lips tasty treat Pita pieces Tibetan Bar Unique flav Tomato Jell yunmy Fishheads Jam Juice 10 20 10 100 50 10 0 5 Days 1 10 Days 0 1 Day 0 30 Days 0 2 Days 0 10 Days 0 1 Day 15 100 20 21 24 12 htons GLU

Explanation / Answer

GetProduct.java

import java.util.*;
import java.io.*;
import java.sql.*;

public class GetProduct
{
  
    private static Scanner sc = new Scanner(System.in);  
  
    public static void main (String args[])
    {
      
        System.out.print("Enter the product ID. ");
      
        String id = sc.next();
      
        getDatabase(id);
    }
  
    private static void getDatabase(String productID){
      
        String className=null;
        String url=null;
        String user = null;
        String password = null;
      
        try
        {
            ResourceBundle resources;
            InputStream in = null;
            ResourceBundle newResources;

            in = ClassLoader.getSystemResourceAsStream("db.properties");

            resources = new PropertyResourceBundle(in);

            in.close();

            className = resources.getString("jdbc.driver");
            url = resources.getString("jdbc.url");
            //System.out.println(url);
            user = resources.getString("jdbc.user");
            password = resources.getString("jdbc.password");
        }
        catch (Exception exp)
        {
            System.out.println("Couldn't load resources." + exp);
            System.exit(-1);
        }
      
        try
        {
            Class.forName(className);
        }
        catch (Exception e)
        {
            System.out.println("Failed to load driver.");
        }
      
        try
        {
             Connection con = DriverManager.getConnection(url,user,password);   
              
            Statement stmt = con.createStatement();
          
            //System.out.print("SELECT ProductName from Inventory WHERE productID = '" + productID + "'");
          
            ResultSet rs = stmt.executeQuery("SELECT ProductName from Inventory WHERE productID = '" + productID + "'");

            while (rs.next())
            {
                String product = rs.getString("ProductName");

                System.out.println("The product name is: '" + product + "'.");
            }
            stmt.close();
      
            con.close();
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
      
    }  
  
}

EE2.java

import java.util.*;
import java.io.*;
import java.sql.*;

public class EE2
{
    public static void main (String args[])
    {
        String className=null;
        String url=null;
        String user = null;
        String password = null;
      
        try
        {
            ResourceBundle resources;
            InputStream in = null;
            ResourceBundle newResources;

            in = ClassLoader.getSystemResourceAsStream("db.properties");

            resources = new PropertyResourceBundle(in);

            in.close();

            className = resources.getString("jdbc.driver");
            url = resources.getString("jdbc.url");
            System.out.println(url);
            user = resources.getString("jdbc.user");
            password = resources.getString("jdbc.password");
        }
        catch (Exception exp)
        {
            System.out.println("Couldn't load resources." + exp);
            System.exit(-1);
        }
      
        try
        {
            Class.forName(className);
        }
        catch (Exception e)
        {
            System.out.println("Failed to load driver.");
            return;
        }
      
        try
        {
             Connection con = DriverManager.getConnection(url,user,password);   
              
            Statement stmt = con.createStatement();
          
            stmt.execute("CREATE TABLE SalesHistory4" +
                         "(ProductID varchar(50)," +
                         "Price int," +
                         "TrnsDate varchar(255)," +
                         "primary key (price)," +
                         "foreign key (ProductID) references Inventory(ProductID))");
      
            System.out.println("Created Sales History table");
      
            stmt.close();
      
            con.close();
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }
}

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