ResultSet warning

In this chapter you will learn:

  1. Checking for a Warning Using a ResultSet Object

Warning message for ResultSet

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
//from  j  a va2  s.  c o  m
public class Main {
  public static void main(String[] args) throws Exception {

    // Get warnings on ResultSet object
    ResultSet rs = null;
    Connection conn = null;
    Statement stmt = null;
    try {
      conn = getConnection(); // get a java.sql.Connection object
      stmt = conn.createStatement(); // create a statement
      // get a result set
      String sqlQuery = "select id, name from employees";
      rs = stmt.executeQuery(sqlQuery);
      while (rs.next()) {
        // use result set
        // 
        // get warnings on the current row of the ResultSet object
        SQLWarning warning = rs.getWarnings();
        if (warning != null) {
          // process result set warnings
        }
      }
    } catch (SQLException e) {
      // ignore the exception
    } finally {
      // close JDBC resources: ResultSet, Statement, Connection
    }

  }

  private static Connection getConnection() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    String url = "jdbc:hsqldb:mem:data/tutorial";

    return DriverManager.getConnection(url, "sa", "");
  }
}

Next chapter...

What you will learn in the next chapter:

  1. Extract information out of SQLWarning
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