Determining If a SQL Warning Occurred - Java JDBC

Java examples for JDBC:SQL Warning

Description

Determining If a SQL Warning Occurred

Demo Code

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLWarning;
import java.sql.Statement;

public class Main {
  public static void main(String[] args) throws Exception {
    Connection connection = null;

    SQLWarning warning = connection.getWarnings();
    while (warning != null) {
        String message = warning.getMessage();
        String sqlState = warning.getSQLState();
        int errorCode = warning.getErrorCode();
        warning = warning.getNextWarning();
    }//from  w w w. java 2 s  .  c o m

    Statement stmt = connection.createStatement();
    // Use the statement...
    warning = stmt.getWarnings();
    if (warning != null) {
        // Process statement warnings...
    }

    ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");
    while (resultSet.next()) {
        // Use result set
        // Get warnings on the current row of the ResultSet object
        warning = resultSet.getWarnings();
        if (warning != null) {
            // Process result set warnings...
        }
    }
  }
}

Related Tutorials