Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc update committed instantly when outside of transaction?

 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is jdbc update committed instantly when outside of transaction? in or out of ejb/web container?
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic