JDBC Tutorial


JDBC Transactions

      JDBC core API supports local transactions. Connection Pooling through DataSource option provides Distributed Transactions support. Connection Interface handles Transactions. Transaction is a set of one or more SQL grouped to do a logical unit of work.

ACID Properties
  • Atomicity: Every Transaction is atmoic,
  • Consistency:Once Transaction is completed whether commit or rollback, Database will be in Consistent State
  • Isolation: Even though transactions execute concurrently,it appears to each transaction T, that others executed either beforeT or After T,but not both
  • Durable:Database server is durable even on abnormal conditions, like power failure, network problem,etc.,

JDBC Isolation Levels

  • Connection.TRANSACTION_READ_UNCOMMITTED
  • Connection.TRANSACTION_READ_COMMITTED
  • Connection.TRANSACTION_REPEATABLE_READ
  • Connection.TRANSACTION_SERIALIZABLE
  • Connection.TRANSACTION_NONE


Dirty Reads

      Dirty Reads occur when transaction reads uncommitted data.

Repeatble Reads

      Repeatable Read occur when one transaction reads committed data.Other Transaction updates the same data. First transaction Reads again in the same Transaction, gets inconsistent data, because first read data and second read data differs in the same transaction itself

Phantom Reads

      Phantom read occurs, when first transaction Reads filtered data with where class, second transaction updates the same data.

ADS