wood burning stoves 2.0*
The moose likes JDBC and the fly likes jdbc update committed instantly when outside of transaction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc update committed instantly when outside of transaction?" Watch "jdbc update committed instantly when outside of transaction?" New topic
Author

jdbc update committed instantly when outside of transaction?

Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2049
is jdbc update committed instantly when outside of transaction? in or out of ejb/web container?
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Jesus,

The answer for your question is : It depends ...

Most databases disable automatic opening transactions by the default so that whenever you open a connection and submit an update, delete or insert statement, they are automatically committed.

However, most of these databases also offer string connection options where you can overwrite this default behavior and tell to database to automatically open a new transaction either whenever a new connection is opened or even right after you explicitly commit an opened transaction.

In MySQL for example, you can force a connection to be "commit aware" in two ways :

Through connection string :
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=monty&password=great&elideSetAutoCommits=true");

or through connection object

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=monty&password=great");

conn.setAutoCommit(false); // Default value is true;

Hope that helps.
[ June 03, 2007: Message edited by: Edisandro Bessa ]

"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2049
Thanks.

I am wondering, when the jdbc update is neither inside programmatic UserTransaction transaction, nor in an ejb method which is on container-transaction 'Required'....

In short, inside ejb business method, a method which is not running in transaction, e.g. 'NotSupported', not even propagated transaction, ... if a jdbc update is basically committed instantly (not considering lazy update by db server).

I guess the answer is yes, it is automatically committed, if transaction is not involved at all; just like in a standalone client doing jdbc updates.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jdbc update committed instantly when outside of transaction?
 
Similar Threads
Does committing transaction closes session?
Not able to add values in a database
oracle - blocking reads
Is this a nested transaction?
How to update an entity when the persistence context is extended?