Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

LAST_INSERT_ID() with threads  RSS feed

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to get the id from a previous insert to use as a foreign ke in another table
I am using the connection pool below in a web application.
Can i use LAST_INSERT_ID() in this configuration whithout the risk of getting the wrong value?

If not what is another way of doing this?

 
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At the very least, you will want to send the LAST_INSERT_ID query to the same connection which did the INSERT statement. None of the code you posted seems to show an example of what you are doing.
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is what i am currently doing but i am using SELECT @@IDENTITY AS IDENTITY
This is giving me a problem so i am looking for an laternative

thanks
john

 
Paul Clapham
Sheriff
Posts: 23714
50
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In that code I don't see where you do an insert before you do the SELECT @@IDENTITY query. Maybe that's your problem.
 
John Schretz
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Clapham wrote:In that code I don't see where you do an insert before you do the SELECT @@IDENTITY query. Maybe that's your problem.



OMG you are the man. That was one of my other problems.
I must have overwrote the execute line when I pasted:


It helps to have a second pair of eyes.
This may relate to the second problem also.

Aside from that do you see any other flaws in the logic?
thanks
john
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!