Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying JDBC 4.0 and Oracle JDeveloper for J2EE Development
  • Table Of Contents Toc
JDBC 4.0 and Oracle JDeveloper for J2EE Development

JDBC 4.0 and Oracle JDeveloper for J2EE Development

3 (2)
close
close
JDBC 4.0 and Oracle JDeveloper for J2EE Development

JDBC 4.0 and Oracle JDeveloper for J2EE Development

3 (2)

Overview of this book

Table of Contents (20 chapters)
close
close
JDBC 4.0 and Oracle JDeveloper for J2EE Development
Credits
About the Author
About the Reviewer
Preface

JDBC Exceptions


SQLException is the main Exception that is generated in a JDBC application. The detail of an SQL exception can be obtained from an SQLException object using the SQLException methods, some of which are discussed in following table:

Method

Description

getMessage()

Returns a textual description of the error.

getSQLState()

Returns a SQLState for the SQLException.

getErrorCode()

Returns the implementation-specific error code for the SQLException object.

getCause()

Returns the cause of the SQLException or null, if the cause is not specified or not known.

getNextException()

Returns an exception chained to the SQLException. All the chained exceptions can be retrieved by invoking the getNextException() method recursively. Returns null, if no chained exception occurs.

getMessage()

Returns a textual description of the error.

When an SQLException occurs, it is likely that one or more SQLExceptions chained to it, have also occurred. The chained exceptions can be retrieved by invoking the getNextException() method recursively, until the method returns null. The cause of an SQLException can be retrieved using the getCause() method. The chained causes can be also be retrieved by invoking the getCause() method recursively, until the value, null, is returned.

If SQLException is generated output the exception message using the getMessage() method, output the exception causes using the getCause() method recursively, and retrieve exceptions chained to the exception using the getNextException() method recursively:

catch(SQLException e)
{
while(e != null)
{
System.out.println("SQLException Message:" + e.getMessage());
Throwable t = e.getCause();
while(t != null)
{
System.out.println("SQLException Cause:" + t);
t = t.getCause();
}
e = e.getNextException();
}
}

Some of the subclasses in the SQLException class are listed in following table:

SQLException

Description

javax.sql.rowset.RowSetWarning

Database warning on a RowSet object.

javax.sql.rowset.serial.SerialException

Indicates an error in the serialization and de-serialization of SQL types such as: BLOB, CLOB, STRUCT, ARRAY.

Java.sql.SQLWarning

Database access warning.

Java.sql.DataTruncation

Indicates data truncation.

Java.sql.BatchUpdateException

Represents an error in a batch update operation.

JDBC 4.0 has added support for categorization of SQLExceptions and enhanced support for chained SQLExceptions, which we will discuss in a later section.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
JDBC 4.0 and Oracle JDeveloper for J2EE Development
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon