Sunteți pe pagina 1din 3

Components of JDBC

JDBC has four main components through which it communicates effectively with the database.

The JDBC API: The JDBC API provides the methods and interfaces for an easy and effective
communication with databases. It provides a standard for connecting the database to the application. The application user processes the SQL commands according to his need and sends back the result to the user. The JDBC API provides two main packages, java.sql and javax.sql, to interact with the database. Both the package contain the Java SE and Java EE platforms, which conform to the write once run anywhere capabilities of Java.

The JDBC Driver Manager: The JDBC Driver Manager is one of the most important components of
JDBC. It manages the different types of database drivers used for a Java application. The main objective of the Driver Manager is to load the database specific drivers in the application. It is also used to select the most database specific driver from the previously loaded drivers when a new connection to a database is established. Driver Manager is also used to make database specific calls to the database to process the user requests.

The JDBC Test Suite: The JDBC Test Suite is used to ensure proper functioning of the JDBC driver. The
test suite tests the JDBC driver based on the JDBC technology. It also ensures the compliance of JDBC driver with the Java application.

The JDBC-ODBC Bridge: The JDBC-ODBC Bridge is used to connect the database drivers to the specific
databases. This driver translates JDBC method calls to ODBC function calls. The bridge is used to implement JDBC for any database that uses an ODBC driver. You can import the sun.jdbc.odbc package to use the JDBC-ODBC Bridge. This package contains a native library for accessing the ODBC features. Features of JDBC The JDBC Metadata API: The Parameter Metadata si an addition to the JDBC metadata API. It is included in the JDBC metadata to describe the parameter properties and their types used in the PreparedStatement interface. Named Parameters: The CallableStatement has been updated by the named parameters; so that users can access the parameters by using the names rather than by using the indexes of the parameters. Changes to data types: The JDBC includes several new and modified data types Large Objects (BLOB, CLOB, REF): The values of the large object types have been modified. ResultSet Values: The JDBC 3.0 also updates the values of the ResultSet as well as the ARRAY types available. New Data Values: JDBC 3.0 includes two new data types, java.sql.Types.DATALINK and java.sql.Types.BOOLEAN. Both the added types update the SQL data types with the same name.

DATALINK data type is accessed by using the getURL() method and the respective value of the Boolean data type is accessed by using the getBoolean() method. Both these methods take an instance of the ResultSet associated with the application. Access to the Auto Generated Keys: This new feature of JDBC 3.0 helps to access the values of the auto generated keys. For doing so, we need to specify Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS in the execute method. The values for the auto generated keys can be accessed in the ResultSet. The ResultSet contains the values for the auto generated keys and the getGeneratedKeys() instance method is used to access the values of the auto generated keys. Connector Relationship: Connector relationship is used to maintain the connection between the JDBC and J2EE. The connector architecture provides a set of connectors through which the enterprise applications connect to JDBC. This connection provides a resource adapter, which is used to connect JDBC to remote systems. The JDBC API provides three main service providers to define the connector architecture. These are described here. ConnectionPoolDataSource: it is an interface provided by the JDBC API. It is used to connect the applications to the JDBC DataSource and the back-end systems. XADataSource: It is used to support the transactional access to the resources. Security Management: This service provider maintains the security mechanism for enterprise applications. A driver vendor is specified to map the JDBC driver to the connector system. Then, the JDBC connector deploys its driver as a resource adapter. ResultSet Functionality: In JDBC programming, we need to close all connections and results manually. JDBC 3.0 supports the functionality of cursor holdability, to ensure that the Connection and ResultSet objects are closed. To maintain the ResultSet holdability within an application, we need to maintain the following constraints. HOLD_CURSOR_OVER_COMMIT- Ensures that ResultSet objects are open even after a commit operation is performed. CLOSE_CURSOR_AT_COMMIT- Ensures that ResultSet objects are closed after a commit operation is performed. Returning Multiple Results: The JDBC 3.0 specification provides a statement interface to access multiple results simultaneously. To access multiple results, the statement includes a new method in the JDBC API. The new method added to the JDBC API is an overloaded form of the getMoreResults() method. It includes an integer flag, which is used to specify the behavior of the ResultSets. The flags included in the JDBC API are. CLOSE_ALL_RESULTS- Close all the previously opened ReslutSets by calling the getMoreResults() method.

CLOSE_CURRENT_RESULT- Closes the current ResultSet object by calling the getMoreResults() method. KEEP_CURRENT_RESULT- Retains the current ResultSet object by using the getMoreResult() method. Connection Pooling: The JDBC 3.0 specification provides the connection pool properties, which allow you to maximize the performance of enterprise applications.

S-ar putea să vă placă și