Hi friends,
I have one doubt in wirting database code in
java..
table a( id , name, description);
table b(id, salary);
I have two table( a & b).. Whenever i insert a record into table a, i need to insert a record in table b also by using primary key of these two tables. we can do it in java. But my problem is that
i am using mysql. i have created a table "A" and make auto increment for column "id". According to mysql, auto increment will generate the unique number automatically.. when we insert a record for table "A",we don't want
to insert a value for column "id" because it will be inserted automatically.
Once a record for table "A" is inserted, i need to get that id from table "A". becos that id value need to be inserted into table "B".
how to do it in java?
There is one way to do it. But i wont like to do that way.
the way is that we should lock the table A and make the select query
and get the nth record and then get the id from n th record.
After that, insert a record into table B using that id getting from select query.
My concern is that i don't want to make select query. Instead of it, get the inserted a record result set and get id from resultset.. ,,, then insert that value into table B....
how can i do this?
can you please tell about it?
what are all ways we can do it