Provides the API for accessing and processing data stored in a data source (usually a relational database) using the Java? Programming language. This API includes a framework whereby different drivers can is installed dynamically to access different data sources. Although the JDBC? API is mainly geared to passing SQL statements to a database, it provides for reading and writing data from any data sourc E with a tabular format. The Reader/writer facility, available through the javax.sql.RowSet
group of interfaces, can be customized-use and update data from A spread sheet, flat file, or any other tabular data source.
What is the JDBC? 4.3 API includes
The JDBC? 4.3 API includes both the package, referred to as the java.sql
JDBC Core API, and javax.sql
the package, referred to as the JDBC Optional Package API. This all JDBC API is included in the Java? Standard Edition (Java SE?), version 7. javax.sql
The package extends the functionality of the JDBC API from a Client-side API to a Server-side API, and it's an esse Ntial part of the Java? Enterprise Edition (Java EE?) technology.
Versions
The JDBC 4.3 API incorporates all of the previous JDBC API versions:
- The JDBC 4.2 API
- The JDBC 4.1 API
- The JDBC 4.0 API
- The JDBC 3.0 API
- The JDBC 2.1 core API
- The JDBC 2.0 Optional package API
(Note that the JDBC 2.1 core API and the JDBC 2.0 Optional package API together is referred to as the JDBC 2.0 API.)
- The JDBC 1.2 API
- The JDBC 1.0 API
Classes, interfaces, methods, fields, constructors, and exceptions had the following "since" tags that indicate when they were introduced into the Java platform. When these "since" tags is used in Javadoc? Comments for the JDBC API, they indicate the following:
- Since 9--New in the JDBC 4.3 API and part of the Java SE platform, version 9
- Since 1.8--New in the JDBC 4.2 API and part of the Java SE platform, version 8
- Since 1.7--New in the JDBC 4.1 API and part of the Java SE platform, version 7
- Since 1.6--New in the JDBC 4.0 API and part of the Java SE platform, version 6
- Since 1.4--New in the JDBC 3.0 API and part of the J2SE platform, version 1.4
- Since 1.2--New in the JDBC 2.0 API and part of the J2SE platform, version 1.2
- Since 1.1 or no "Since" tag--in the original JDBC 1.0 APIs and part of the JDK?, version 1.1
Note: Many of the new features is optional; Consequently, there is some variation in drivers and the features they support. Always check the your driver ' s documentation to see whether it supports a feature before you try to use it.
Note: The class SQLPermission
is added in the Java 2 SDK, Standard Edition, version 1.3 release. This class was used to prevent unauthorized access to the logging stream associated DriverManager
with the, which may contain infor Mation such as table names, column data, and so on.
What the
java.sql
Package Contains
The package java.sql
contains API for the following:
- Making a connection with a database via the
drivermanager
facility
-
Drivermana GER
class--Makes a connection with a driver
-
sqlpermission
class--Provides per Mission when code running within a Security Manager, such as a applets, attempts to set up a logging stream through THE&NB Sp DriverManager
-
Driver
interface--provides the API for registering and connecting drivers based on JDBC technology ("JDBC drivers"); Generally used only by the DriverManager
class
-
driverpropertyinfo
class--Provides properties for a JDBC driver; Not used by the general user
- Sending SQL statements to a database
Statement
--Used to send basic SQL statements
PreparedStatement
--Used to send prepared statements or basic SQL statements (derived from Statement
)
CallableStatement
--Used to called database stored procedures (derived from PreparedStatement
)
Connection
Interface--Provides methods for creating statements and managing connections and their properties
Savepoint
--Provides savepoints in a transaction
- Retrieving and updating the results of a query
- Standard mappings for SQL types to classes and interfaces in the Java programming language
Array
interface--Mapping for SQLARRAY
Blob
interface--Mapping for SQLBLOB
Clob
interface--Mapping for SQLCLOB
Date
Class--Mapping for SQLDATE
NClob
interface--Mapping for SQLNCLOB
Ref
interface--Mapping for SQLREF
RowId
interface--Mapping for SQLROWID
Struct
interface--Mapping for SQLSTRUCT
SQLXML
interface--Mapping for SQLXML
Time
Class--Mapping for SQLTIME
Timestamp
Class--Mapping for SQLTIMESTAMP
Types
Class--Provides constants for SQL types
- Custom Mapping an SQL user-defined type (UDT) to a class in the Java programming language
SQLData
Interface--Specifies the mapping of a UDT to an instance of this class
SQLInput
Interface--Provides methods for reading UDTs attributes from a stream
SQLOutput
Interface--Provides methods for writing UDTs attributes back to a stream
- Metadata
DatabaseMetaData
Interface--Provides information about the database
ResultSetMetaData
Interface--Provides information about the columns of a ResultSet
object
ParameterMetaData
Interface--Provides information about the parameters to PreparedStatement
commands
- Exceptions
SQLException
--thrown by most methods when there are a problem accessing data and by some methods for other reasons
SQLWarning
--thrown to indicate a warning
DataTruncation
--thrown to indicate the data may be been truncated
BatchUpdateException
--thrown to indicate and not all commands in a batch update executed successfully
java.sql
and
javax.sql
Features introduced in the JDBC 4.3 API
- Added Support
Sharding
- Enhanced to being
Connection
able to provide hints to the driver this a request, an independent unit of work, is beginning or Endi Ng
- Enhanced to
DatabaseMetaData
determine if sharding is supported
- Added the method
drivers
to DriverManager
return a Stream of the currently loaded and available JDBC drivers
- Added Support-to-
Statement
enquoting literals and simple identifiers
- Clarified the Java SE version that methods were deprecated
java.sql
and
javax.sql
Features introduced in the JDBC 4.2 API
- Added
JDBCType
enum and SQLType
interface
- Support for in
REF CURSORS
CallableStatement
DatabaseMetaData
Methods to return maximum Logical LOB size and if Ref Cursors is supported
- Added support for large update counts
java.sql
and
javax.sql
Features introduced in the JDBC 4.1 API
- Allow
Connection
, and objects to is used with the ResultSet
Statement
try-with-resources statement
- Support added to and to
CallableStatement
ResultSet
specify the Java type to convert to via the getObject
method
DatabaseMetaData
Methods to return Pseudocolumns and if a generated key are always returned
- Added support
Connection
To specify a database schema, abort and timeout a physical connection.
- Added support to close a
Statement
object when its dependent objects has been closed
- Support for obtaining the parent logger for a
Driver
, DataSource
, and ConnectionPoolDataSource
XADataSource
java.sql
and
javax.sql
Features introduced in the JDBC 4.0 API
- Auto Java.sql.Driver Discovery--no longer need to load a
java.sql.Driver
class viaClass.forName
- National Character Set Support added
- Support added for the sql:2003 XML data type
- SQLException Enhancements--Added support for cause chaining; New SQLExceptions added for common SQLState class value codes
- Enhanced BLOB/CLOB functionality--support provided to create and free a Blob/clob instance as well as additional methods Added to improve accessibility
- Support added for accessing a SQL ROWID
- Support added to allow a JDBC application to access a instance of a JDBC resource that have been wrapped by a vendor, Usua Lly in an application server or connection pooling environment.
- Availability to being notified when a that's
PreparedStatement
associated with a have PooledConnection
been closed or the driver determines is inval Id
java.sql
and
javax.sql
Features introduced in the JDBC 3.0 API
- Pooled statements--reuse of statements associated with a pooled connection
- Savepoints--Allow a transaction to being rolled back to a designated savepoint
- Properties defined for
ConnectionPoolDataSource
--Specify how connections is to be pooled
- Metadata for parameters of a
PreparedStatement
object
- Ability to retrieve values from automatically generated columns
- Ability to has multiple
ResultSet
objects returned from CallableStatement
objects open at the same time
- Ability to identify parameters to objects by name as well as by
CallableStatement
index
ResultSet
Holdability--Ability to specify whether cursors should is held open or closed at the end of a transaction
- Ability to retrieve and update the SQL structured type instance a
Ref
object references
- Ability to programmatically update,,
BLOB
CLOB
ARRAY
, and REF
values.
- Addition of the
java.sql.Types.DATALINK
data type--allows JDBC drivers access to objects stored outside a data source
- Addition of metadata for retrieving SQL type hierarchies
java.sql
Features introduced in the JDBC 2.1 Core API
- Scrollable result sets--using new methods in the interface and the cursor to being
ResultSet
moved to a particular row or To a position relative to their current position
- Batch Updates
- Programmatic updates--using
ResultSet
Updater Methods
- New Data types--interfaces Mapping the SQL3 data types
- Custom Mapping of user-defined types (UDTs)
- Miscellaneous features, including performance hints, the use of character streams, full precision for
java.math.BigDecimal
values, Additi Onal security, and support for time zones in date, time, and timestamp values.
javax.sql
Features introduced in the JDBC 2.0 Optional package API
- The
DataSource
interface as a means of making a connection. The Java naming and Directory Interface? (JNDI) is used-registering a DataSource
object with a naming service and also for retrieving it.
- Pooled connections--allowing connections to be used and reused
- Distributed transactions--allowing a transaction to span diverse DBMS servers
RowSet
Technology--providing a convenient means of handling and passing data
Custom Mapping of UDTs
A user-defined type (UDT) defined in SQL can is mapped to a class in the Java programming language. An SQL structured type or an SQL type is the UDTs that is May DISTINCT
custom mapped. The following three steps set up a custom mapping:
- Defining the SQL structured type or
DISTINCT
type in SQL
- Defining the class in the Java programming language to which the SQL UDT would be mapped. This class must implement the
SQLData
interface.
- Making an entry in a
Connection
object ' s type, map, contains, and things:
- The fully-qualified SQL name of the UDT
- The object for the class, that
Class
implements the SQLData
interface
When these is in place for a UDTs, calling the methods ResultSet.getObject
or on that CallableStatement.getObject
UDT would automatically retrieve the custom m Apping for it. Also, the PreparedStatement.setObject
method would automatically map the object back to its SQL type to store it in the data source.
Package specification
Related documentation
- Lesson:jdbc Basics (The Javaxx tutorials > JDBC? Database Access)
- Jdbc? API Tutorial and Reference, third Edition
Package java.sql