0

Ok
I know many of you already done with this sort of situation
i have a form which have few fields and on submitting that form i want these field values save into two tables.
Both the tables contains a primary key and foriegn key.
Let table one have id as PK and table 2 has id as FK in that table so in this way these two tables are related to each other.
I am not getting how will i code to insert data in both tables in single funtion and using the PK and Fk constriant.

2
Contributors
6
Replies
30
Views
4 Years
Discussion Span
Last Post by ruchi18
0

Let table one have id as PK and table 2 has id as FK in that table so in this way these two tables are related to each other.
I am not getting how will i code to insert data in both tables in single funtion and using the PK and Fk constriant.

I think your question is more related to the database rather than JSP.

You are talking about a query to let you insert data into the tables?

If yes, then it's about a query.

Then post your table structure.

Anything dealing with database needs a query regardless of what language either PHP, ASP.Net adn etc. Once you have a query then you need to implement the code to your JSP.

0

yupp i think i am not getting query for this:

Table 1 has 3 fields
id, name and password where id is primary key
Table 2 has 6-7 fields
name, address, city, age, gender etc and id as reference key from table 1.

So i need to insert datain both these table using a single query.
How do i acheive this.

0

What database are you using?

MYSQL/MSSQL/Oracle or something else?

What are you trying to INSERT here (it's more like an admin table)? :

//Table 1 has 3 fields
id, name and password where id is primary key

What column data do you want to INSERT here?:

//Table 2 has 6-7 fields
name, address, city, age, gender etc and id as reference key from table 1.

Edited by LastMitch: grammer

0

i am using oracle 11g.
The scenario is like i have a registration form which contains all this fields and on registering the user i have to insert data in these two tables.
First username and password insert and then userdetail will insert in another table according to userid which is in uesrname password Table1 .
If i am going wrong then please explain me further it will help me alot.

Thanks

0

First username and password insert and then userdetail will insert in another table according to userid which is in uesrname password Table1 .

It sounds like if you want to JOIN a table? I'm a bit confused about user detail?

For example look at this query's INSERT:

INSERT INTO candy (mint candy) VALUES (mint);

The example I mention is that I insert mint candy to a new variable mint.

INSERT INTO state (state_abbrev) VALUES ('WA');

The example I mention is that I insert state_abbrev to a new variable WA.

I hope you can see how a INSERT works.

So base on the comment you mention you want the query to look like this:

INSERT INTO Table 1 (name, password) VALUES ('$name', '$password');

or this:

INSERT INTO Table 1 (name, password) VALUES ('$username', '$password');

I mean so far how do you want your query in Table 2? As for Table 1 the only query that make sense is this:

INSERT INTO Table 1 (name, password) VALUES ('$username', '$password');

You can JOIN (name, password) from Table 1 to Table 2.

I be honest with you I got no idea why you want to INSERT (name, password) when you can just JOIN the column to Table 2.

I hope understand how a INSERT looks like with your Table 1. I got no idea what you are trying to do.

Edited by LastMitch: grammer

0

Thanks
But I understand insert query very well.
The problem is different.
Let me try 1 more time if you understand.
As database must be nomarlized we can not insert all values in a single table.
Now let take an example if the view page contains "username, name, age, address" and I want to insert "username, name and age" in userdetails table and address in another table useraddress.
Now how would i achieve this by single insert button click event.

Hope it will more clear to you what i want to ask.

Thanks

N congrates you have completed 2500 posts at this forum :-)

Edited by ruchi18

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.