Adv Java - [JDBC: SQL Classes]

♠ Posted by Unknown in at 01:15

JDBC SQL Classes


The JDBC classes and interfaces remain in two Java packages : java.sql and javax.sql:

  1. java.sql :- This package contains classes and interfaces designed with traditional client-server architecture in mind. Its functionality is focused primarily on basic database programming services such as creating connections, executing statements and prepared statements, and running batch queries. Advanced functions such as batch updates, scrollable resultsets, transaction isolation, and SQL data types are also available.
  2. javax.sql :- This package introduces some major architectural changes to JDBC programming compared to java.sql, and provides better abstractions for connection management, distributed transactions, and legacy connectivity. This package also introduces container-managed connection pooling, distributed transactions, and rowsets.
The classes in the java.sql package can be divided into the following groups based on their functionality:

  1. Connection Management :- The following classes/interfaces let you establish a connection to the database. In most cases, this involves a network connection:
java.sql.DriverManager, java.sql.Driver, java.sql.DriverPropertyInfo, java.sql.Connection

  1. Database Access :- Once you obtain a connection, the following classes/interfaces let you send SQL statements to the database for execution and read the results:
java.sql.Statement, java.sql.PreparedStatement, java.sql.CallableStatment, java.sql.ResultSet,

The java.sql.PreparedStatement and java.sql.CallableStatement extend java.sql.Statement. All the three interfaces are conceptually similar, each offering a means of sending requests to execute SQL statements and obtaining the results of execution.

  1. Data Types :- The java.sql package also provides several Java data types that correspond to some fo the SQL types. You can use one of the following types as appropriate depending on what a field in a result row corresponds to in the database: java.sql.Array, java.sql.Blob; java.sql.Clob; java.sql.Date; java.sql.Time; java.sql.Tiimestamp; java.sql.Ref; java.sql.Struct; java.sql.Types.
The JDBC API also includes facilities for dealing with custom database types. These types can be represented as java.sql.SQLData objects, and data within these types can be accessed using java.sql.SQLInput and java.sql.Output interfaces that provide a stream like interface to accessing data.

  1. Database Metadata :- The JDBC API also includes facilities to obtain metadata about the database, parameters to statements, and result: java.sql.DatabaseMetadata, java.sql.ResultMetadata, java.sql.ParameterMetadata
  1. Exceptions and Warnings :- The following classes encapsulate database access errors and warnings: java.sql.SQLException, java.sql.SQLWarning, java.sql.BatchUpdateException, java.sql.DataTruncation.

0 comments:

Post a Comment