This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Queries not committing in transaction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Queries not committing in transaction" Watch "Queries not committing in transaction" New topic

Queries not committing in transaction

Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
I have this JDBC code where I need to insert a record and then get the id of that inserted column. Everything works fine until I run a threaded test that tries to do 10 of these at once. The problem is that everything seems to run OK. The log prints out the id. But when I query the database only the last record was inserted. All the others are not persisted. No exceptions are thrown.

So for each call two queries are being run. Even though these are being run in different threads, only the last one works. If I run them sequentially, not in threads, it all works.

The problem really being I am running this in a threaded environment in production...

The squeaky wheel gets the grease. Well, that or replaced...
Rusty Enisin
Ranch Hand

Joined: May 26, 2005
Posts: 107
Arg. You work on something all morning and then finally post in desperation, only to figure it out 10 minutes later... I should have posted hours ago. Then I would have figured it out hours ago + 10 minutes...

The SQL for the identity select was incorrect. I was using this which is wrong:

This is wrong, wrong, wrong. And needless to say caused me heartburn. Here is the correct SQL.

I agree. Here's the link:
subject: Queries not committing in transaction
It's not a secret anymore!