Question: JAVA. SQL . I want the parent class to be author and the child class to be books. Creating a one to many relationship. Please
JAVA. SQL
I want the parent class to be author and the child class to be books. Creating a one to many relationship. Please explain the code.
Write a textbased, Java program. Everything will be done in Java: creating and dropping tables, inserting, deleting and updating tables. At the end of your
program, be sure to drop your tables, which means that every time you run your program, you will be creating the tables. Modularize your code. Your methods should not contain more than lines. Display a menu that allows the user to insert, delete, update or view all the records.
Insert
Delete
Update
View
Quit
Insert upon choosing insert, ask the user a series of questions that map the response to the different columns in your tables.
Lets take the Candidate and the Party tables as an example. With candidate name, john and political party, republican, you would
have to create an entry in the party table if a record does not exist for the republican party and a corresponding record in the
candidate table for John. You would have to make sure that the foreign keys and primary keys are assigned properly. You can use
sequences to generate your primary keys.
Delete You would ask for some kind of unique information that identifies a record in the child table and then delete the record.
If there are no other instances of the foreign key, then also delete the record from the parent table. For example, if we look up john
and he is the only republican, then we would delete both john from the candidate table and republican from the party table.
Update You would ask for some kind of unique information that identifies a record in the parent table must be unique and
then ask what the information should be changed to such as
What party do you want to change? Republican
What do you want to change it to Conservative
View Display all the records in the child table and their corresponding information from the parent table. Make sure to not
include the primary and foreign keys. Here is a sample
John Republican
Jim Democrat
Jill Independent
quit end the program
import java.sql;
class Driver
public static void mainString argsthrows Exception
DriverManager.registerDriver new oracle.jdbcdriver.OracleDriver;
Connection conDriverManager.getConnection
jdbc:oracle:thin:@sabzevihomeip.net::orcl", "csus", "student";
Statement stcon.createStatement;
try
stexecuteQuerydrop table test";
catch SQLException e
System.out.println the error is e
stexecuteQuerycreate table test col number, col number;
stexecuteQueryinsert into test values ;
ResultSet rsstexecuteQueryselect from test ;
while rsnext
System.out.printrsgetStringrsgetString;
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
