aspose file tools*
The moose likes JDBC and the fly likes transaction when we Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "transaction when we "select" data from db ?" Watch "transaction when we "select" data from db ?" New topic
Author

transaction when we "select" data from db ?

Edward Chen
Ranch Hand

Joined: Dec 23, 2003
Posts: 798

Do we need a transaction when we "select" data from db ? The coding is below, though it is hibernate version.

Thanks.

David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Depends what you want to do with the data. If you plan on updating the data but there was no transaction, then there would be no guarantee on the data at the point you go to save your records.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3611
    
  60

This may strongly depend on the database. In Oracle, for example, you can start the transaction in serializable mode (or read-only mode for that matter, though JDBC does not directly support read-only transactions) and all your selects will return data as they existed at the time the transaction started. This may be important in regard to the consistency of data being read.

In other databases the transaction (and its isolation level) might affect the results in different ways.
 
 
subject: transaction when we "select" data from db ?