Handling a SQL Exception - Java JDBC

Java examples for JDBC:SQL Warning

Description

Handling a SQL Exception

import java.sql.Connection;
import java.sql.SQLException;

public class Main {

  public static void main(String[] argv) {
    Connection connection = null;
    try {
      // Execute SQL statements...
    } catch (SQLException e) {
      while (e != null) {
        String message = e.getMessage();

        String sqlState = e.getSQLState();

        int errorCode = e.getErrorCode();
        // Get driver name
        String driverName = connection.getMetaData().getDriverName();
        if (driverName.equals("Oracle JDBC Driver") && errorCode == 123) {
          // Process error...
        }
        e = e.getNextException();
      }
    }
  }
}

Related Tutorials