Question: Question 2 You are provided with a SQL file named data.sql that contains SQL statements to create and populate a Cars table. Here is the
Question
You are provided with a SQL file named data.sql that contains SQL statements to create and populate a Cars table. Here is the data.sql code below: Connect to or create the CarDB database
CONNECT jdbc:derby:CarDB;createtrue';
Drop the table if it already exists to avoid conflicts
DROP TABLE Cars;
Create the Cars table
CREATE TABLE Cars
id INT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
make VARCHAR
model VARCHAR
manufactureyear INT,
price DECIMAL
;
Insert sample records into the Cars table
INSERT INTO Cars make model, manufactureyear, price
VALUES Toyota 'Corolla', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Ford 'Mustang', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Honda 'Civic', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Chevrolet 'Camaro', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES BMW Series', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES AudiA;
INSERT INTO Cars make model, manufactureyear, price
VALUES MercedesBenz', CClass', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Tesla 'Model ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Hyundai 'Elantra', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Kia 'Optima', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Volkswagen 'Jetta', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Nissan 'Altima', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Mazda 'Mazda;
INSERT INTO Cars make model, manufactureyear, price
VALUES Subaru 'Impreza', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Jeep 'Wrangler', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Dodge 'Charger', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES VolvoS;
INSERT INTO Cars make model, manufactureyear, price
VALUES Porsche 'Cayenne', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Ferrari Spider', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Lamborghini 'Huracan', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Bentley 'Continental GT;
INSERT INTO Cars make model, manufactureyear, price
VALUES RollsRoyce', 'Phantom', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Ford 'Explorer', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Chevrolet 'Tahoe', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES BMWX;
INSERT INTO Cars make model, manufactureyear, price
VALUES MercedesBenz', 'GLE', ;
INSERT INTO Cars make model, manufactureyear, price
VALUES Toyota 'RAV;
INSERT INTO Cars make model, manufactureyear, price
VALUES HondaCRV;
INSERT INTO Cars make model, manufactureyear, price
VALUES AudiQ;
INSERT INTO Cars make model, manufactureyear, price
VALUES LexusRX;
Commit the transaction
COMMIT;
Verify the content of the Cars table optional
SELECT FROM Cars;
Your Task:
Create a new database called CarShop.
Import the data.sql file into your CarShop database to create and popu
late the Cars table.
You are required to write a Java program that connects to the CarShop database
and presents a menu to the user. The program should use a SELECT FROM
CARS query to retrieve all records from the Cars table and perform tasks by
processing the ResultSet.
The following code is provided:
The function should prompt the user to enter a manufacture year.
The function should output the number of cars available for that year.
You are only allowed to use the SELECT FROM CARS query; you may
not use any other SQL statements to accomplish the task.
All logic should be implemented by working with the ResultSet obtained
from the SELECT query.
Instructions:
Complete the missing code in the main method to establish the database
connection and exec
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
