Simple question about an insert query...

G

gbattine

excume me guys,
i've a problem and i need your help.
I'm developing a jsf application.
I've 2 mysql tables

experiment(id_exp(autoincremented), name, author)
sample(id_sample(autoincremented),id_exp,value)

My application performs inserting into the 2 table.
My question is:
when i do insert in experiment in my query i don't use id_exp attribute
because it's autoincremented and everythings go well.

Later i've to insert more samples entities in sample table relating to
the same experiment inserted,that is i've more samples for the same
experiment.
What have i pass in my insert query on sample for id_exp to reference
the experiment autoincremented id before inserted?
I have to do everythings in one transaction(the 2 insert queries)..
can you help me?
Thanks very much
 
M

Moiristo

gbattine said:
excume me guys,
i've a problem and i need your help.
I'm developing a jsf application.
I've 2 mysql tables

experiment(id_exp(autoincremented), name, author)
sample(id_sample(autoincremented),id_exp,value)

My application performs inserting into the 2 table.
My question is:
when i do insert in experiment in my query i don't use id_exp attribute
because it's autoincremented and everythings go well.

Later i've to insert more samples entities in sample table relating to
the same experiment inserted,that is i've more samples for the same
experiment.
What have i pass in my insert query on sample for id_exp to reference
the experiment autoincremented id before inserted?
I have to do everythings in one transaction(the 2 insert queries)..
can you help me?

I have about the same question. Consider a transaction where the first
insert statement creates an ID that I need for two other queries in the
same transaction. How can this be done? When I just create a transaction
(autocommit false), a deadlock occurs. I'm using j2ee with the latest
mysql connector on mysql5.
 
T

Thomas Kellerer

excume me guys,
i've a problem and i need your help.
I'm developing a jsf application.
I've 2 mysql tables

experiment(id_exp(autoincremented), name, author)
sample(id_sample(autoincremented),id_exp,value)

My application performs inserting into the 2 table.
My question is:
when i do insert in experiment in my query i don't use id_exp attribute
because it's autoincremented and everythings go well.

Later i've to insert more samples entities in sample table relating to
the same experiment inserted,that is i've more samples for the same
experiment.
What have i pass in my insert query on sample for id_exp to reference
the experiment autoincremented id before inserted?
I have to do everythings in one transaction(the 2 insert queries)..
can you help me?
Thanks very much


getGeneratedKeys() should return the generated IDs:

http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#getGeneratedKeys()

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top