How to get stored variable value from mysql transaction -


i have written transaction mysql innodb engine. has insert in table auto generate key, insert using auto generate key got using last_insert_id(). after second insert have several inserts need foreign key auto generated key last table in have inserted. did made variable , used of them. now, need auto generated key value returned in java program can use it. how do it? transaction large here trying do.

start transaction; insert a(value) values(123); insert b(aid,value) values((select last_insert_id()),345); set @key = ( select last_insert_id() ) ; insert c(val,fk) values(1,@key); insert c(val,fk) values(2,@key); insert c(val,fk) values(3,@key); ..... insert c(val,fk) values(10,@key); 

now need @key variable value returned in program. java program using j connector mysql (if matters).

mysql variables session-scoped can following anywhere want long you're using same connection :

select @key; 

for more information, manual friend : https://dev.mysql.com/doc/refman/5.0/en/user-variables.html


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -