The JDBC Support Classes
JDBC provides a handful of other
classes and interfaces that support JDBC’s core functionality.
Many of them are more SQL-friendly extensions of
java.util
classes like
java.sql.Date
and
java.sql.Numeric
. Others are exception classes
that get thrown by JDBC calls.
java.sql.Types
The
Types
class provides
constants that identify SQL datatypes. Each constant representing a
SQL datatype that is mapped to an integer is defined by the XOPEN SQL
specification. You will see this class used extensively in the next
chapter.
java.sql.SQLException
The SQLException
class
extends the general java.lang.Exception
class that
provides extra information about a database error. The information
provided by SQLException
includes:
The SQLState string describing the error according to the XOPEN SQLState conventions. The different values of this string are defined in the XOPEN SQL specification.
The database-specific vendor error code. This code is usually a number you have to look up in the obscure reference section of your database’s documentation. Fortunately, the error should be sufficiently described through the Java
Exception
class’sgetMessage()
method.A chain of exceptions leading up to this one. This is one of the niftier features of this class. Specifically, if you get several errors during the execution of a transaction, they can be piggybacked in this class. This is frequently useful when you have exceptions that you want to inform the user of, but you do not want to ...
Get Database Programming with JDBC & Java, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.