SQLException 類提供了關(guān)于數(shù)據(jù)庫訪問錯誤的信息。
每個 SQLException 提供了幾種信息:
- 一個描述錯誤的一個字符串。它被用作 Java Exception 消息,并可通過調(diào)用 getMesage() 方法使用它。
- 一個遵守 XOPEN SQLstate 約定的字符串 "SQLstate"。
SQLState 字符串的值由 XOPEN SQL spec 約定描述。
- 一個供應商專用的整數(shù)錯誤代碼。通常它是由當前使用的數(shù)據(jù)庫返回的實際的錯誤代碼。
- 到下一個
Exception 的鏈。 它可以用來提供附加的錯誤信息。
類 java.sql.SQLException
java.lang.Object
|
+----java.lang.Throwable
|
+----java.lang.Exception
|
+----java.sql.SQLException
- public class SQLException
- extends Exception
- 下列類的父類:
- SQLWarning
構(gòu)造子索引
- SQLException()
- 構(gòu)造一個 SQLException;reason 缺省為 null,SQLState 缺省為
null 且 vendorCode 缺省為 0。
- SQLException(String)
- 用一個 reason 構(gòu)造一個 SQLException;SQLState 缺省為
null 且 vendorCode 缺省為 0。
- SQLException(String, String)
- 用一個 reason 和 SQLState 構(gòu)造一個 SQLException;vendorCode 缺省為 0。
- SQLException(String, String, int)
- 構(gòu)造一個指定全部參數(shù)的 SQLException。
方法索引
- getErrorCode()
- 獲得供應商專用的異常代碼
- getNextException()
- 獲得與該異常相鏈接的下一個異常。
- getSQLState()
- 獲得 SQLState
- setNextException(SQLException)
- 在鏈的末端添加一個 SQLException 。
構(gòu)造子
SQLException
public SQLException(String reason,
String SQLState,
int vendorCode)
- 構(gòu)造一個指定全部參數(shù)的 SQLException。
- 參數(shù):
- reason - 異常的描述
- SQLState - 標識異常的 XOPEN 代碼
- vendorCode - 一個數(shù)據(jù)庫 vendor specific 異常代碼
SQLException
public SQLException(String reason,
String SQLState)
- 用一個 reason 和 SQLState 構(gòu)造一個 SQLException;vendorCode 缺省為 0。
- 參數(shù):
- reason - 異常的描述
- SQLState - 標識異常的 XOPEN 代碼
SQLException
public SQLException(String reason)
- 用一個 reason 構(gòu)造一個 SQLException;SQLState 缺省為
null 且 vendorCode 缺省為 0。
- 參數(shù):
- reason - 異常的描述
SQLException
public SQLException()
- 構(gòu)造一個 SQLException;reason 缺省為 null,SQLState 缺省為
null 且 vendorCode 缺省為 0。
方法
getSQLState
public String getSQLState()
- 獲得 SQLState
- 返回值:
- SQLState 值
getErrorCode
public int getErrorCode()
- 獲得供應商專用的異常代碼
- 返回值:
- 供應商的錯誤代碼
getNextException
public SQLException getNextException()
- 獲得與該異常相鏈接的異常。
- 返回值:
- 鏈中的下一個 SQLException ,如果沒有則為 null
setNextException
public synchronized void setNextException(SQLException ex)
- 在鏈的末端添加一個 SQLException 。
- 參數(shù):
- ex - SQLException 鏈新的結(jié)尾