This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Our software doesn't use EJBs but rather accesses database directly. For example, a certain servlet could call several methods, each of them obtaining a separate connection from the datasource and using it to update database. Since there are several connections, connection.setAutoCommit(false) obviously won't work. I was wondering if it's possible to execute all this db calls as part of one transaction. Any suggestions or samples would be appreciated.
Check out UserTransactions and TransactionManager. I haven't tried it in WebSphere, let alone in a Servlet or library code, but from memory something like this may work: The UserTranaction is an interface, the factory to obtain one is registered in JNDI. It would look like this:
Also be aware that it may be bound in JNDI as javax.transaction.UserTransaction, I can't remember... It is also a common practice to wrap the ut.begin/commit around a single method that does all the SQL.