Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6068153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:41:06+00:00 2026-05-23T09:41:06+00:00

In JDBC the Connection , Statement , and ResultSet types each have a getWarnings()

  • 0

In JDBC the Connection, Statement, and ResultSet types each have a getWarnings() method that is specified to produce the first warning associated with objects of that type. The second and subsequent warnings, if they exist, are chained onto the first warning (if it even exists, null is produced if there are no warnings).

The specs say that warnings associated with objects of these types are cleared after certain actions. For example warnings on a ResultSet are cleared when each new row is read.

The SQLWarning type is a subtype of SQLException. So would the presence of a warning be indicated by an exception? And that exception would be chained to the associated object if the exception’s runtime type is SQLWarning?

What I’m wondering is this, and it might be driver specific, how do I know when I should call getWarnings() and expect a non-null response? Put another way, is a warning present on a JDBC object and available with getWarnings() only after that object has thrown an exception? (and that exception is the warning?)

Should I call getWarnings() to look for warnings after every JDBC operation “just to be sure” if my goal is to observe every warning?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:41:06+00:00Added an answer on May 23, 2026 at 9:41 am

    SQLWarning objects are a subclass of SQLException that deal with database access warnings.

    Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned.

    A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object.

    Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object:

    SQLWarning warning = stmt.getWarnings();
    if (warning != null)
    {
        System.out.println(\"n---Warning---n\");
        while (warning != null)
        {
            System.out.println(\"Message: \" + warning.getMessage());
            System.out.println(\"SQLState: \" + warning.getSQLState());
            System.out.print(\"Vendor error code: \");
            System.out.println(warning.getErrorCode());
            System.out.println(\"\");
            warning = warning.getNextWarning();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The JDBC 3.0 spec talks about Connection (and Prepared Statement) pooling. We have several
I'm using JDBC for very simple database connectivity. I have created my connection/statement and
currently i have jdbc code with the following basic stucture: get Connection (do the
I am using Oracle 9 JDBC Thin Driver - the connection string I have
Our standard code section for using JDBC is... Connection conn = getConnection(...); Statement stmt
I need to test a JDBC connection to a database. The java code to
I'm using a vendor API to obtain a JDBC connection to the application's database.
How do I check for an open connection in jdbc for oracle database? Note:
I've executed a JDBC query to obtain a resultset. Before iterating over it, I'd
When using JDBC, I often come across constructs like ResultSet rs = ps.executeQuery(); while

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.