-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Brian,
On 5/26/2011 8:41 PM, Brian Braun wrote: > I have an application that, so far, hasn't had transactional processing. I > mean I have the autocommit in "on" mode, so every update/delete gets > commited separately. I need to fix it so it starts grouping changes to the > DB in a transaction and implement the ACID stuff, using the commit and > rollback. Note that this question has very little to do with Tomcat itself. > I read the documentation and it is not hard, but I have two > complications: > > 1- I'm using DBCP, the connection pool: The way I have programmed my app is > that a business object asks a resultset that comes after a query, which in > turn asks for a statement, which in turn asks for a connection from the > pool. That means that the business object dosn't know which connection from > the pool will attend its requirement at the end. What should I do? Should I > start asking the pool for a connection, set the autocommit to "false", use > this connection for all the changes I need to make, then commit (or > rollback), and then at the end "close" (return to the pool) the connection? > Is that it? Yes. The default status of a JDBC Connector is spec-defined to be in auto-commit mode. The best thing to do is to set autocommit to false, do your stuff, then commit. Might I also suggest looking at this post: http://blog.christopherschultz.net/index.php/2009/03/16/properly-handling-pooled-jdbc-connections/ > 2- My app uses two databases, even though both run inside the same MySQL > instance. I mantain two DBCP pools, one for each database. Then how do I > manage the transactions, if I need to make changes to both databases and > that implies using two different connections? Do I need to use the JTA stuff > that Java EE brings, for distributed processing, or is there an easier > approach? As Martin suggests, you'll need to use a more complicated transaction manager to do these kinds of things. Since you're using MySQL, you might even be able to get away with obtaining a single connection that has access to both databases. If you database-qualify your table names, I believe that transactions can span multiple databases. Note that not all MySQL storage engines support transactions: I believe only InnoDB and NDBCLUSTER tables support transactions, so you should double-check to see what storage engine you are using. - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk3lRUUACgkQ9CaO5/Lv0PBEDQCdGFz7y8KtrVThzzw5ek4yjSsA IDYAoMLJtC1QigeVt5KrMUgkOETy+gsI =cuYG -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org