Pages

Subscribe:

Ads 468x60px

Tuesday, November 1, 2011

The Connection Class

The Connection class is one of the major classes in JDBC. It packs a lot of functionality, ranging from transaction processing to creating statements. Another important function performed by the Connection object is the transaction management. The handling of the transactions depends on the state of an internal autocommit flag that is set using the setAutoCommit() method, and the state of this flag can be read using the getAutoCommit() method. When the flag is true, the transactions are automatically committed as soon as they are completed. There is no need for any intervention or commands from the Java application program. When the flag is false, the system is in the system is in the Manual mode. The Java program has the option to commit the set of transactions that happened after the last commit or roll back the transactions using the commit() and rollback() methods.

JDBC also provides methods for setting the transaction isolation modularity. When you are developing multi-tiered applications, multiple users will be performing concurrently interleaved transactions that are on the same database tables. A database driver has to employ sophisticated locking and data buffering algorithms and mechanisms to implement the transaction isolation required for a large-scale JDBC application. This is more complex when there are multiple Java objects working on many database that could be scattered across the globe.
After you have a successful Connection object to a data source, you can interact with the data source in many ways. The most common approach, from an application developer standpoint, is using the objects that handle the SQL statements. In JDBC, there are three main types of statements:

  •   Statement
  •   PreparedStatement
  •   CallableStatment

The Connection object has the createStatement(), prepareStatement(), and prepareCall() methods to create these statement object. Another notable method in the Connection object is the getMetadata() method that returns an object of the DatabaseMetadata type.

No comments:

Post a Comment