This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
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: 2053
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: 2053
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.
 
Don't get me started about those stupid light bulbs.
 
subject: jdbc update committed instantly when outside of transaction?