Q&A

Q1:Which JDBC driver is best for my J2EE applications?
A1: Each JDBC driver has its usage environment and depends on the availability of the driver. Type 2 is best used when high transaction rate is required because itís optimized for the native DBMS API. Type 4 is all Java, and is attractive for most J2EE applications because itís optimized with the underlying JVM technology.
Q2:What is the appropriate sequence to access a DataSource through JDBC?
A2: There are two important group of tasks to be performed: one by the administrator and the other by the application developer.

The administrative tasks are

  • Configure a DataSource and registered it in into the JNDI service provider.

  • Configure a connection pool and map it to the defined DataSource.

The developer writes code in the following sequence:

  • Connect to a JNDI service, and establish a Context by looking up a named DataSource.

  • Create a Connection object from the DataSource factory. A Connection is assigned from the connection pool. A Connection represents a database session.

  • Create a Statement object from Connection (can be PreparedStatement or CallableStatment).

  • Perform SQL statements (both DDL and DML database operations) on the Statement object, such as execute(), executeQuery(), updateQuery(), and executeBatch().

  • Retrieve output in a ResultSet object, and process it according to the application's needs.

  • Close all allocated resources in proper sequence: First, close all Statement objects in the reverse order of how they were allocated, then close the Connection objects, and finally the Context object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.124.21