db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Van Couvering <da...@vancouvering.com>
Subject Re: Single Transaction Using Multiple Method Calls That Open New Database Connections
Date Fri, 16 Feb 2007 01:48:49 GMT
Sheesh, I forgot about this.  I've actually done that before.  This is 
part of my local calendar demo; see how I use thread local storage to 
keep a connection.  This is in the Derby codeline...


Craig L Russell wrote:
> Hi Sisilla,
> You might look at using a java.lang.ThreadLocal to store the Connection 
> or some object that stores more state including the Connection.
> Since you don't have to pass the Connection through multiple layers, it 
> can make your code simpler and less "messy".
> Craig
> On Feb 15, 2007, at 9:24 AM, Sisilla wrote:
>> Thank you very much, David. I appreciate your time and consideration. 
>> I chose
>> to use one Connection Object and pass it to all my methods so no new
>> connections were opened. It makes my code messier, but I don't know 
>> anything
>> about JTA. Again, thanks for the suggestion. ~Sisilla
>> David Van Couvering-2 wrote:
>>> If you're using multiple connections, then you need to use JTA to have
>>> it work in a single transaction, and your database driver needs to
>>> support XA.
>>> If you're running in a J2EE environment with declarative transaction
>>> management enabled, you're good to go.
>>> If you're running in a web container, you may be able to get a reference
>>> to a UserTransaction object through JNDI (look up UserTransaction in
>>> Google).  Some web containers provide JTA support, others don't and
>>> you'll need to get it from a third party.
>>> Others may provide details and/or corrections to what I say here, but
>>> that's the general idea.
>>> David
>>> Sisilla wrote:
>>>> Hello All,
>>>> I would like to update several tables in one transaction. The updates
>>>> happen
>>>> via several method calls, and each of these methods open new database
>>>> connections. The methods also contain calls to other methods that open
>>>> new
>>>> database connections. Is it at all possible that these updates could be
>>>> handled as a single transaction without eliminating these method calls?
>>>> I am using
>>>>                     conn.setAutoCommit(false);
>>>> before the updates and
>>>>                     conn.commit();
>>>> after the updates, but it isn't working as is.
>>>> I am using Derby and JDK 1.6.0 on Windows XP Professional. I
>>>> appreciate any help.
>>>> Thanks,
>>>> Sisilla
>> --View this message in context: 
>> http://www.nabble.com/Single-Transaction-Using-Multiple-Method-Calls-That-Open-New-Database-Connections-tf3228984.html#a8989769

>> Sent from the Apache Derby Users mailing list archive at Nabble.com.
> Craig Russell
> clr@apache.org http://db.apache.org/jdo

View raw message