SQL Exception

In this chapter you will learn:

  1. What are the exceptions in JDBC
  2. java.sql.SQLException Methods

Exceptions in JDBC

java.sql.SQLException extends the java.lang.Exception class. java.sql.SQLException is a core JDBC exception class that provides information about database access errors and other errors. Most of the JDBC API methods throw SQLException.

java.sql.BatchUpdateException is an Exception that provides the update counts for all commands that were executed successfully during the batch update.

java.sql.DataTruncation reports a Data Truncation warning (on reads) or throws a DataTruncation exception (on writes) when JDBC unexpectedly truncates a data value.

java.sql.SQLWarning provides information about database access warnings.

java.sql.SQLException Methods

Return Type Method Description
int getErrorCode()Retrieves the vendor-specific exception code for this SQLException object
SQLExceptiongetNextException() Retrieves the exception chained to this SQLException object
String getSQLState() Retrieves the SQLState for this SQLException object
void setNextException(SQLException ex) Adds a SQLException object to the end of the chain

Next chapter...

What you will learn in the next chapter:

  1. Extracting Information from SQLException
  2. Get the Details of a SQLException
  3. Print the stack trace for a SQLException to STDERR
Home » Java Tutorial » Statements, ResultSet, Exception, Warning

Statement

    Three types of statements
    Statement interface
    Insert
    Delete records
    Drop a table
    Batch operation

PreparedStatement

    PreparedStatement
    Insert
    Delete
    Update with parameters
    Batch operation
    ParameterMetaData
    Fetch size
    Set null vaue

CallableStatement

    CallableStatement

ResultSet

    ResultSet
    ResultSet Type
    ResultSet Concurrency
    Create a ResultSet
    ResultSet reading
    ResultSet get by column name
    ResultSet get column by index
    ResultSet next row
    ResultSet table row count
    ResultSet navigation
    ResultSet cursor forward and backward
    ResultSet first
    ResultSet last
    ResultSet after last
    ResultSet before first
    ResultSet absolute(2)
    ResultSet absolute(-1)
    ResultSet relative(-2)
    ResultSet relative(-2)
    ResultSet update
    Column Names
    Column count
    Column Characteristics

ResultSetMetaData

    Column Names
    Column count
    Column Characteristics

SQL Exception, SQL Warning

    SQL Exception
    SQLException information
    Chaining SQLExceptions
    Connection Warning
    PreparedStatement SQLWarning
    Statement SQLWarning
    ResultSet warning
    SQLWarning information