O'Reilly logo

Database Programming with JDBC & Java, Second Edition by George Reese

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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’s getMessage() 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required