Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (2.6k points)
closed by

I am using jsp with mysql database,Its an isa relation type,I have created a table named product which has a "product_id" as the primary key, and also I have created two other tables named "spare_parts" and "accessories" which doesn't has the primary key but have foreign key of product table. now depending on form submission I want to insert my data in either of the tables. please help

closed

4 Answers

0 votes
by (11.4k points)
 
Best answer
In your JSP application with a MySQL database, you have implemented an ISA relation type using three tables: "product," "spare_parts," and "accessories." The "product" table has a primary key column called "product_id," while the other two tables have foreign key columns referencing "product_id." Depending on form submission, you need to insert data into either the "spare_parts" or "accessories" table. To achieve this, retrieve the form data, determine its type, and then insert it into the corresponding table while including the appropriate "product_id" as a foreign key.
0 votes
by (7.2k points)
edited by

To insert values in MYSQL database, you need to use this command...

INSERT INTO table_name (column1, column2, column3, ...)

VALUES (value1, value2, value3, ...);

Intellipaat provides Online SQL Training for its learners.

0 votes
by (7.8k points)
- You have a JSP application that uses a MySQL database and implements an ISA (is-a) relation type.

- The database schema includes three tables: "product," "spare_parts," and "accessories."

- The "product" table has a primary key column called "product_id."

- Both the "spare_parts" and "accessories" tables have a foreign key column referencing the "product_id" column in the "product" table.

- Depending on form submission, you need to insert data into either the "spare_parts" table or the "accessories" table.

To achieve this, you can follow these steps:

1. Retrieve the form submission data and determine whether it belongs to a spare part or an accessory.

2. If it is for a spare part, insert the data into the "spare_parts" table. Ensure that you include the corresponding "product_id" as a foreign key.

3. If it is for an accessory, insert the data into the "accessories" table, again including the appropriate "product_id" as a foreign key.

4. Make sure to handle any potential errors during the insertion process, such as duplicate entries or missing data validation.

5. Finally, provide appropriate feedback to the user indicating the success or failure of the insertion operation.

By following these steps, you can dynamically insert data into the appropriate table based on the form submission in your JSP application.
0 votes
by (13k points)

You can insert form data into either the "spare_parts" or "accessories" table based on its type, while including the related "product_id" as a foreign key.

Related questions

0 votes
1 answer
asked Dec 18, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
4 answers
0 votes
1 answer

Browse Categories

...