What are the important methods of the SQLException class?

JDBCJava 8MySQLMySQLi Database

An SQLException can occur both in the driver and the database. When such an exception occurs, an object of type SQLException will be passed to the catch clause.

The passed SQLException object has the following methods available for retrieving additional information about the exception:

getErrorCode( )Gets the error number associated with the exception.
getMessage( )Gets the JDBC driver's error message for an error, handled by the driver or gets the Oracle error number and message for a database error.
getSQLState( )Gets the XOPEN SQLstate string. For a JDBC driver error, no useful information is returned from this method. For a database error, the five-digit XOPEN SQLstate code is returned. This method can return null.
getNextException( )Gets the next Exception object in the exception chain.
printStackTrace( )Prints the current exception, or throwable, and it's backtrace to a standard error stream.
printStackTrace(PrintStream s)Prints this throwable and its backtrace to the print stream you specify.
printStackTrace(PrintWriter w)Prints this throwable and it's backtrace to the print writer you specify.
Published on 20-Mar-2019 12:08:25