Hi, somewhere in my program I try to get the generated keys of my insert statement. However, I set auto commit to false. Will getGeneratedKeys() work even when I set to autocommit false? Here's my sample code...
I would avoid using getGeneratedKeys() altogether (although I can greatly understand your desire to use it), it is barely supported by most drivers/dbs such that you can't really rely on. I think only got it to work once out of a number of tries.
Generating keys and using those values is a non-trivial matter. One solution (most common) is to always query for the max row after you create a record. If done as part of a transaction there are ways to make this somewhat safe.
Another solution I prefer is to not use database generated keys but generate the keys yourself. This probably has the best success since you never have to worry about someone else getting your key... if your insert fails (assuming the column is a key and/or unique) the transaction will roll back. Of course, there are ways of preventing that by using a static key generator.