官术网_书友最值得收藏!

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:

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:

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

主站蜘蛛池模板: 甘泉县| 遂溪县| 鄂托克旗| 三原县| 铁岭市| 五指山市| 习水县| 垣曲县| 繁昌县| 莎车县| 安远县| 台东县| 九寨沟县| 密云县| 绥德县| 百色市| 西峡县| 嵊泗县| 和林格尔县| 临清市| 景泰县| 武陟县| 万盛区| 泽普县| 咸丰县| 渭南市| 繁峙县| 贡觉县| 铜陵市| 平原县| 尼勒克县| 安乡县| 皮山县| 卫辉市| 精河县| 长子县| 固始县| 仁化县| 高陵县| 玛多县| 呼伦贝尔市|