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 text-based, 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 20 lines. Display a menu that allows the user to insert, delete, update or view all the records.
1) Insert
2) Delete
3) Update
4) View
5) Quit
1) 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.
2) 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.
3) 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
4) 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
5. quit - end the program
import java.sql.*;
class Driver{
public static void main(String[] args)throws Exception{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@sabzevi2.homeip.net:1521:orcl", "csus", "student");
Statement st=con.createStatement();
try {
st.executeQuery("drop table test");
} catch (SQLException e){
System.out.println( the error is + e)
}
st.executeQuery("create table test (col1 number, col2 number)");
st.executeQuery("insert into test values (15,16)");
ResultSet rs=st.executeQuery("select * from test ");
while (rs.next())
System.out.print(rs.getString(1)+""+rs.getString(2));
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!