110 lines
7.3 KiB
HTML
110 lines
7.3 KiB
HTML
|
<?xml version="1.0" encoding="UTF-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html lang="en-us" xml:lang="en-us">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta name="security" content="public" />
|
||
|
<meta name="Robots" content="index,follow" />
|
||
|
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
|
||
|
<meta name="DC.Type" content="concept" />
|
||
|
<meta name="DC.Title" content="SQLException" />
|
||
|
<meta name="abstract" content="The SQLException class and its subtypes provide information about errors and warnings that occur while a data source is being accessed." />
|
||
|
<meta name="description" content="The SQLException class and its subtypes provide information about errors and warnings that occur while a data source is being accessed." />
|
||
|
<meta name="DC.Relation" scheme="URI" content="exceptin.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="sqlwarng.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="datatruk.htm" />
|
||
|
<meta name="DC.Relation" scheme="URI" content="exceptionexample.htm" />
|
||
|
<meta name="copyright" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 2006" />
|
||
|
<meta name="DC.Format" content="XHTML" />
|
||
|
<meta name="DC.Identifier" content="exceptions" />
|
||
|
<meta name="DC.Language" content="en-us" />
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
|
||
|
<link rel="stylesheet" type="text/css" href="./ic.css" />
|
||
|
<title>SQLException</title>
|
||
|
</head>
|
||
|
<body id="exceptions"><a name="exceptions"><!-- --></a>
|
||
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
||
|
<h1 class="topictitle1">SQLException</h1>
|
||
|
<div><p>The SQLException class and its subtypes provide information about
|
||
|
errors and warnings that occur while a data source is being accessed.</p>
|
||
|
<p>Unlike most of JDBC, which is defined by interfaces, the exception support
|
||
|
is provided in classes. The base class for exceptions that occur while running
|
||
|
JDBC applications is SQLException. Every method of the JDBC API is declared
|
||
|
as being able to throw SQLExceptions. SQLException is an extension of java.lang.Exception
|
||
|
and provides additional information related to failures that happen in a database
|
||
|
context. Specifically, the following information is available from an SQLException:</p>
|
||
|
<ul><li>Text description</li>
|
||
|
<li>SQLState</li>
|
||
|
<li>Error code</li>
|
||
|
<li>A reference to any other exceptions that also occurred</li>
|
||
|
</ul>
|
||
|
<p><a href="exceptionexample.htm">ExceptionExample</a> is
|
||
|
a program that properly handles catching an (expected in this case) SQLException
|
||
|
and dumping all the information that it provides.</p>
|
||
|
<div class="note"><span class="notetitle">Note:</span> JDBC provides a mechanism where exceptions can be chained together.
|
||
|
This allows the driver or the database to report multiple errors on a single
|
||
|
request. There are currently no instances where the native JDBC driver would
|
||
|
do this. This information is only provided as reference and not a clear indication
|
||
|
that the driver never does this in the future however.</div>
|
||
|
<p>As noted, SQLException objects are thrown when errors occur. This is correct,
|
||
|
but is not the complete picture. In practice, the native JDBC driver rarely
|
||
|
throws actual SQLExceptions. It throws instances of its own SQLException subclasses.
|
||
|
This allows you to determine more information about what has actually failed
|
||
|
as is shown below.</p>
|
||
|
<div class="section"><h4 class="sectiontitle">DB2Exception.java</h4><p>DB2Exception objects are not thrown
|
||
|
directly either. This base class is used to hold functionality that is common
|
||
|
to all JDBC exceptions. There are two subclasses of this class that are be
|
||
|
the standard exceptions that JDBC throws. These subclasses are DB2DBException.java
|
||
|
and DB2JDBCException.java. DB2DBExceptions are exceptions that are reported
|
||
|
to you that have come directly from the database. DB2JDBCExceptions are thrown
|
||
|
when the JDBC driver finds problems on its own. Splitting the exception class
|
||
|
hierarchy in this manner allows you to handle the two types of exceptions
|
||
|
differently.</p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">DB2DBException.java</h4><p>As stated, DB2DBExceptions are
|
||
|
exceptions that come directly from the database. These are encountered when
|
||
|
the JDBC driver make a call to the CLI and gets back an SQLERROR return code.
|
||
|
The CLI function SQLError is called to get the message text, SQLState, and
|
||
|
vendor code in these cases. The replacement text for the SQLMessage is also
|
||
|
retrieved and returned to you. The DatabaseException class causes an error
|
||
|
that the database recognizes and reports to the JDBC driver to build the exception
|
||
|
object for.</p>
|
||
|
</div>
|
||
|
<div class="section"><h4 class="sectiontitle">DB2JDBCException.java</h4><p>DB2JDBCExceptions are generated
|
||
|
for error conditions that come from the JDBC driver itself. The functionality
|
||
|
of this exception class is fundamentally different; the JDBC driver itself
|
||
|
handles message language translation of exception and other issues that the
|
||
|
operating system and database handle for exceptions originating within the
|
||
|
database. Wherever possible, the JDBC driver adheres to the SQLStates of the
|
||
|
database. The vendor code for exceptions that the JDBC driver throws is always
|
||
|
-99999. DB2DBExceptions that are recognized and returned by the CLI layer
|
||
|
often also have the -99999 error code. The JDBCException class causes an error
|
||
|
that the JDBC driver recognizes and builds the exception for itself. When
|
||
|
run during development of the release, the following output was created. Notice
|
||
|
that the top of the stack contains DB2JDBCException. This is an indication
|
||
|
that the error is being reported from the JDBC driver prior to ever making
|
||
|
the request to the database. </p>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div>
|
||
|
<ul class="ullinks">
|
||
|
<li class="ulchildlink"><strong><a href="exceptionexample.htm">Example: SQLException</a></strong><br />
|
||
|
This is an example of catching an SQLException and dumping all the information that it provides.</li>
|
||
|
</ul>
|
||
|
|
||
|
<div class="familylinks">
|
||
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="exceptin.htm" title="The Java language uses exceptions to provide error-handling capabilities for its programs. An exception is an event that occurs when you run your program that disrupts the normal flow of instructions.">Exceptions</a></div>
|
||
|
</div>
|
||
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
||
|
<div><a href="sqlwarng.htm" title="Methods in some interfaces generate an SQLWarning object if the methods cause a database access warning.">SQLWarning</a></div>
|
||
|
<div><a href="datatruk.htm" title="DataTruncation is a subclass of SQLWarning. While SQLWarnings are not thrown, DataTruncation objects are sometimes thrown and attached like other SQLWarning objects. Silent truncation occurs when the size of a column exceeds the size specified by the setMaxFieldSize statement method, but no warning or exception is reported.">DataTruncation and silent truncation</a></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|